我正在尝试让我的代码为我的游戏调整变量。然而,即使currWeather不等于“非常热”,它也只运行第一个if语句。它应检查当前的天气,然后根据if语句调整正确的变量。
function checkWeather(){
if(currWeather = "Very Hot"){
health -= 8;
milesPerDay *= 0.7;
console.log("subtracted");
}
else if(currWeather = "Hot"){
health -= 3;
milesPerDay *= 0.9;
console.log("subtracted");
}
else if(currWeather = "Warm"){
health += 1;
milesPerDay *= 1;
console.log("subtracted");
}
else if(currWeather = "Cool"){
health += 1;
milesPerDay *= 0.95;
console.log("subtracted");
}
else if(currWeather = "Cold"){
health -= 5;
milesPerDay *= 0.8;
console.log("subtracted");
}
else if(currWeather = "Very Cold"){
health -= 12;
milesPerDay *= 0.7;
console.log("subtracted");
}
else if(currWeather = "Rain"){
health -= 4;
milesPerDay *= 0.6;
console.log("subtracted");
}
else if(currWeather = "Heavy Rain"){
health -= 8;
milesPerDay *= 0.4;
console.log("subtracted");
}
else if(currWeather = "Snow"){
health -= 15;
milesPerDay *= 0.3;
console.log("subtracted");
}
else if(currWeather = "Blizzard"){
health -= 30;
milesPerDay *= 0.1;
console.log("subtracted");
}
else if(currWeather = "Heavy Fog"){
health -= 3;
milesPerDay *= 0.5;
console.log("subtracted");
}
else{
health += 0;
milesPerDay *= 1;
console.log("ez");
}
console.log("test");
}