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

我有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可能不符合您的期望.看一下逻辑运算符,即&&和||

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...