-4

i have some code here and im struggling to find out what it going wrong, i know some of the javascript is wrong, but how would i correct it, many thanks

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Numbers Games</title>
<link rel="stylesheet" type="text/css" href="style-home.css">
</head>

<body>
<div id="header"
<h1>Numbers Game</h1>
</div>
<p id="ParQuestion">What is five thousand and thirty three in numbers.</p>
<input id="txt_Ans" type="text" />
<input id="btn_Start" type="button" value="Start"                   

onclick="btn_Start_OnClick()" /><br />  
<input id="btn_Check" type="button" value="Check"      onclick="btn_Check_OnlClick()" />


<div id="Scoreboard">
<img id="scoreOn1" src="Pictures/Scorefaceoff1.gif" height="50px"        width="50px" /> 
<img id="scoreOn2" src="Pictures/Scorefaceoff2.gif" height="50px" width="50px" /> 
<img id="scoreOn3" src="Pictures/Scorefaceoff3.gif" height="50px" width="50px" /> 
<img id="scoreOn4" src="Pictures/Scorefaceoff4.gif" height="50px" width="50px" /> 
<img id="scoreOn5" src="Pictures/Scorefaceoff5.gif" height="50px" width="50px" />
</div>

<p id="ParComment"></p>

</body>


</html>
<script language="javascript">

    function btn_Check_OnClick(){
       if txt_Ans.value = "5033"
        parRes.InnerText=ParComment.value;
    }else{
        ParComment.InnerText="Wrong, Try Again";
    }
    }
</sript>
Marc B
  • 356,200
  • 43
  • 426
  • 500
  • 3
    Welcome to Stackoverflow. What do you think it is ? what have you done so far ? In order for us to help you got to show that you did actual research. :) – Nelson Teixeira Nov 24 '15 at 15:25
  • 2
    And having said that, `btn_Check_onlClick()`? Where's that particular function defined? and you have an extra `}` in your script block to begin with. – Marc B Nov 24 '15 at 15:29

4 Answers4

1

Just commenting on the script block:

  • Your closing tag says "sript", not "script"
  • Your if statement has syntax errors, it is missing (, ) and {
  • Your if statement is assigning when it should be comparing; use == over = in conditions
  • The property is called innerText, not InnerText
  • ParComment doesn't have a value property
David Hedlund
  • 128,221
  • 31
  • 203
  • 222
0

First of all your "</sript>" tag -> "</script>"

"if txt_Ans.value = "5033"" -> "if (txt_Ans.value == "5033"){ parRes.InnerText=ParComment.value; }"

Close your "div-tag" on line 10.

Edit: First of all try to use a code checker like "http://jshint.com/" for syntax errors

Y.Hermes
  • 449
  • 5
  • 22
0

I think you didn't add an opening script tag. Also, you should add parenthesis on your if statements. And instead of using = to compare use == instead. Also, get elements using document.getElementById

Try this:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Numbers Games</title>
<link rel="stylesheet" type="text/css" href="style-home.css">
</head>

<body>
<div id="header"
<h1>Numbers Game</h1>
</div>
<p id="ParQuestion">What is five thousand and thirty three in numbers.</p>
<input id="txt_Ans" type="text" />
<input id="btn_Start" type="button" value="Start"                   

onclick="btn_Start_OnClick()" /><br />  
<input id="btn_Check" type="button" value="Check"      onclick="btn_Check_OnlClick()" />


<div id="Scoreboard">
<img id="scoreOn1" src="Pictures/Scorefaceoff1.gif" height="50px"        width="50px" /> 
<img id="scoreOn2" src="Pictures/Scorefaceoff2.gif" height="50px" width="50px" /> 
<img id="scoreOn3" src="Pictures/Scorefaceoff3.gif" height="50px" width="50px" /> 
<img id="scoreOn4" src="Pictures/Scorefaceoff4.gif" height="50px" width="50px" /> 
<img id="scoreOn5" src="Pictures/Scorefaceoff5.gif" height="50px" width="50px" />
</div>

<p id="ParComment"></p>

<script>
    function btn_Check_OnClick(){
       if(document.getElementById('txt_Ans').value == "5033"){
           parRes.InnerText=ParComment.value;
       }else{
           document.getElementById('ParComment').innerHTML = "Wrong, Try Again";
       }
    }
</sript>
</html>

It's best practice to put your script inside html tag

Miguel Ike
  • 484
  • 1
  • 6
  • 19
0

One thing others haven't mentioned is <div id="header" is missing the closing >. You have a lot of syntax errors that others did mention, though.

You'd benefit a lot by looking at this in your browsers development tools. With most modern browsers, just press F12 to open them. I'm sure you'll probably get a few JavaScript errors showing in the console. That's a good place to start.

For your other syntax errors, here's a few places to look at:

Community
  • 1
  • 1
neilsimp1
  • 1,242
  • 1
  • 11
  • 25