The alert() command pops up a notification box in the user’s browser containing whatever data is between the parentheses.
When you press Return or Enter, the browser displays an alert message containing the message “Good job!”
You display numbers in alerts by putting numbers without quotes between the parentheses. For example, try this statement:
The alert pop‐up displays the number 300. You can even do math inside an alert. For example, try this one:
The alert displays the result of multiplying 37 and 37.
var myNameIs = "your name"; alert(myNameIs);
The browser pops up a window containing your name.
var firstName = "your name"; var yourScore = 30; alert("Hi, " + firstName + ". Your current score is: " + yourScore);
As you can see, by using alert(), you can create all sorts of fun and interesting pop‐ups to entertain and inform the user, such as the alert shown here.
One way to make changes to the current web page is by using the write method.
A method is something that can be done or that something can do.
document.write("Hi, Mom!"); document.write(333 + 100);
Notice that statements after the first one are added right after the first statement, without a line break or space. You can add space after or before writing text with document.write by using the characters <br>. For example:
document.write("How are you?<br>"); document.write("I'm great! Thanks!<br>"); document.write("That's awesome!");
You can clear out the current contents of the browser window by typing chrome://newtab into the browser address bar or by opening a new browser tab.
<br> is an HTML tag.