在我必须做的一件简单的事情中,赋值中的左侧无效

Invalid left-hand side in assignment in a simple thing I have to do

本文关键字:赋值 无效 简单的事 一件 必须做      更新时间:2023-09-26

因此,在为该代码赋值时,我在第12行(var声明所在的位置)得到错误Invalid left side:

<html>
  <head>Guessing Game</head>
  <body>
    <p>"Hello! Welcome to the Guessing Game of Life or Slavery. Remember to use correct spelling and punctuation!"</p>
    <form id ="q1" action = "">
      "What is the meaning of life the universe and everything?"
      <input type = "text" >
    </form>
    <script>
      var answerOne = function(){
        var theAnswer = "42"
        if("text" == theAnswer){
          prompt("TEST!")
        }
      }
    </script>
  </body>
</html>

我只是测试一下。。。我真正想做的是制作一个网页,在那里我回答了这个问题,上面写着"你就在网页上

这就是你需要的吗?:

<script>
function answerOne(){
var theAnswer = "42"
    var answerGiven= document.getElementById('answer').value;
  if(answerGiven == theAnswer){
         //code for correct answer
         alert("correct");
    }
  else {
      //code for incorrect answer
      alert("incorrect");
  }
}
</script>
</head>
<body>
<p>"Hello! Welcome to the Guessing Game of Life or Slavery. Remember to use correct spelling and punctuation!"</p>
<form id ="q1" action = "" onsubmit="answerswerOne();" >
  "What is the meaning of life the universe and everything?"
  <input type = "text" id="answerswer">
  <input type="submit" value="Submit"  >
 </form>

注意:表单验证未完成,需要在用户输入任何无效值时进行