在条件问题中编码JavaScript

时间:2016-01-03 20:50:24

标签: javascript conditional-statements

我知道这是基本的JavaScript:当我用HTML打开它时,它会问我这个问题,但是当我回答问题时,却没有完成下一行代码。我现在不知道为什么这样做,我真的很感激一些帮助。

<html>
<head>hi</head>
<script>if ( confirm("do you want to do the quiz") === true ) {
console.log("good")
}
else
{
console.log("ok")
 }
if ( prompt("What is the capital of france?") === "Paris" ) {
Console.log("that is right")
}
else
{
consle.log("unlucky")
}


</script>
</html>

3 个答案:

答案 0 :(得分:1)

您拼错了控制台,JavaScript也是一种区分大小写的语言,因此无法将控制台编写为控制台

试试这个

if ( confirm("do you want to do the quiz") === true ) {
console.log("good")
}
else
{
console.log("ok")
 }
if ( prompt("What is the capital of france?") === "Paris" ) {
console.log("that is right")
}
else
{
console.log("unlucky")
}

答案 1 :(得分:0)

请试试这个,你在两个地方拼错了console.log

<html>
<head>hi</head>
<script>if ( confirm("do you want to do the quiz") === true ) {
console.log("good")
}
else
{
console.log("ok")
 }
if ( prompt("What is the capital of france?") === "Paris" ) {
console.log("that is right")
}
else
{
console.log("unlucky")
}


</script>
</html>

答案 2 :(得分:0)

我认为你问用户是否想要玩测验,如果用户选择了确定,那么你继续测验。为此,您需要使用console.log(“good”);

添加if块中的所有测验部分
if(confirm("wanna play quiz?")){
   // start quiz
   if(prompt("question")=="answer"){
      console.log("That's right")
   }
   // more questions...
}