gpt4 book ai didi

javascript - 尝试从提示中 console.log 2 输入

转载 作者:行者123 更新时间:2023-11-29 10:56:55 25 4
gpt4 key购买 nike

我有 2 个问题希望用户回答并希望 console.log 将这些答案放在一起。我已经成功解决了 1 个问题,但无法弄清楚如何获得 2 个问题。我知道我离题太远了,但这就是我目前所拥有的。

        var EventType = prompt("What kind of Event are you attending?");
var tempFahr = prompt("What is the temperature?");

if( EventType == "semi-formal" ) {
console.log("Wear a polo ");
} else if( EventType == "casual" ) {
console.log("Wear something comfy ");
} else if( EventType == "formal" ) {
console.log("Wear a suit");
} else {
console.log("Wear nothing!");
}


if( tempFahr <= 70 ) {
console.log("It is hot outside!");
} else if( tempFahr >= 54 ) {
console.log("It's chilly outside!");
} else if( tempFahr < 54 + >70 ) {
console.log("It is pleasant outside");
} else {
console.log("Who cares about the weather,");
}

最佳答案

有几种方法可以解决这个问题,但最简单的方法可能就是分配给结果变量。

    var EventType = prompt("What kind of Event are you attending?");
var tempFahr = prompt("What is the temperature?");

var recommendedClothing
if( EventType == "semi-formal" ) {
recommendedClothing = "Wear a polo ";
} else if( EventType == "casual" ) {
recommendedClothing = "Wear something comfy ";
} else if( EventType == "formal" ) {
recommendedClothing = "Wear a suit";
} else {
recommendedClothing = "Wear nothing!";
}

var weatherAssessment
if( tempFahr <= 70 ) {
weatherAssessment = "It is hot outside!";
} else if( tempFahr >= 54 ) {
weatherAssessment = "It's chilly outside!";
} else if( tempFahr < 54 || tempFahr > 70 ) {
weatherAssessment = "It is pleasant outside";
} else {
weatherAssessment = "Who cares about the weather,";
}

console.log(recommendedClothing + ' ' + weatherAssessment)

编辑

一些其他注意事项,因为看起来您可能仍在学习(很好的第一个问题,顺便说一句!)

  • 为您的变量选择一致的大小写(我可能会将 EventType 重命名为 eventType,因此它与 tempFahr 的大小写相同)
  • 54 + >70 可能没有按照您的预期运行。查看逻辑运算符,即 &&||

关于javascript - 尝试从提示中 console.log 2 输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55280184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com