We are starting to program with JavaScript We are starting to program with JavaScript. Here are a series of examples. Once you have opened them, you can see the HTML code by viewing the course.
This is the first example This is the first example. It writes on the document or screen and it brings up an alert.
The alert, pops up a screen with what is inside the parenthesis The alert, pops up a screen with what is inside the parenthesis. Again it is a literal and that is what appeared in the alert box.
This is the second example, it has a prompt that asks the user for input.
I define the memory variables I am using in the program. message appears above the box where the user enters information. Then I write on the document the contents of the parenthesis which is ans. I write the contents of the memory variable ans.
First I write the literal "The answer is" and then I write what is stored in the memory variable ans.
in concatenated. When I made sure I had numbers, it added. Note that JavaScript is case sensitive so it has to be written as parseFloat with a capital F and parseInt with a capital I.
This is parseInt. When I want to skip down to the next line, I can document write the html <br>. I put it inside quotes and it then uses the <br> and writes the line.
A single = means assign. In the calculation I multiply or divide firstnum and secondnum and assign the answer to ans.
Note this means that an end if is not needed because I tell it everything I want to do if I execute the if and everything I want to do if I execute the else.
it is a /.
the second if and wrote out the 0 for ans.