So, now we know document.write();, lets learn how to use alert(). The alert() function creates one of those incredibly irritating alert box pop ups. It is a handy (and irritating) way of alerting users of stuff, like input errors and whatnot. It goes like so:
Ok, so in javacsript a variable is declared like so:
var name = "Billy-bob";
In the above, we are creating a variable (var) called name, who’s value is “Billy-bob”. We are then alerting that variable. Simple? Yes! Now lets try some logic, let’s add some stuff together:
var mynumber = 5;
var answer = 0;
answer = mynumber + 8;
You see what we did there? We created a variable called mynumber (which we gave a value of 5). We created a variable called answer (which we gave an initial value of 0). We the redeclared our variable number to equal the sum of our first variable, mynumber, and 8. We then alerted that.