【发布时间】:2018-06-20 16:57:49
【问题描述】:
所以我的最终目标是能够为酒店和用户计算媒人。我将有问题让用户通过提示输入,我将使用它来匹配我提供的酒店详细信息并输出以显示哪些酒店最适合用户。目前我的疑问是:
//Hotel choices
const minStar = prompt("What is the minimum star rating you would like?");
if (minStar==5)
{console.log(`That sounds grand`);}
else
{console.log(`Just ${minStar}, huh?`);}
const distCityMax = prompt("What is the furthest distance in miles from a city you would be happy with?");
console.log(`${distCityMax} miles maximum from a city`);
const wifi = prompt("Do you require WiFi?");
console.log(`Do you require wifi? ${minStar}`);
const swimPool = prompt("Is a swimming pool important?");
console.log(`Your decision on a swimming pool was: ${swimPool}`);
目前我只需要找到一个示例酒店的匹配项:
let passed=true;
if(minStar!=5){
passed=false;
}
if(distCityMax>=1){
passed=false;
}
if(wifi!=="yes"){
passed=false;
}
if(swimPoo!=="yes"){
passed=false;
}
if(passed===true){
console.log("These hotels would suit you: TheGrand");
}else{
console.log("There are no matching hotels");
}
但我无法弄清楚,即使在尝试了在论坛上发布的类似内容之后,如何能够计算所有“错误”被击中的次数,以便我可以计算它们并与它们一起显示百分比。
tldr;如何计算“passed=false”的次数?
【问题讨论】:
-
只需创建一个变量并增加计数。
标签: javascript loops counter