TEST AND DEBUG YOUR CODE

Remember to test your code, and if your script includes user input, be sure to test it out with different kinds of data to see how it performs. Depending on the script, you may want to test the following:

  • an octal number (such as 0300)
  • a floating-point number (such as 1.2)
  • text

If you don't understand the results you're getting from your script, try testing it by inserting alert statements to find out the value of a variable at various stages in your script, such as

var myFirstValue = prompt 
("Enter a number","");
alert(myFirstValue);
var mySecondValue = prompt 
("What's your age?","");
alert(mySecondValue);

You can add as many alerts as you need during testing and then remove them after your script has been tested and debugged.