This code introduces the if statement, a powerful programming tool. Here, we use if to check the information entered on a form. Note the double equals sign (= =) tests equality, whereas a single equals sign reassigns a variable.
<form name="ifForm"> Please enter the word 'computer' (without the quotes) below:<br> <input type="text" name="theWord"> <input type="button" value="Check Me" onClick="checkWord(ifForm.theWord.value)"> </form>
<script language="JavaScript"><!--
function checkWord(text1){
if (text1=='computer'){//compare the input string with the string 'computer'
alert('You were correct!');//this line executed if above statement was TRUE
}
else {
alert('Incorrect! You wrote ' +text1+ '. Please try again');//this line executed if the statement was FALSE
}
}
// --></script>