We are starting JavaScript. Here are a set of examples We are starting JavaScript. Here are a set of examples. Remember that after you click on them and open them you can use view source to see the code.
The first program writes on the document and also brings up a pop up that says Hello World!
Note the semi-colon at the end of each line.
This is another program where I am bringing up a prompt to ask the user for input. Notice the mesage in the prompt that says Enter the first number. There was a default 0 in the box, I entered a 3 so that is what you are seeing.
First I define three memory variables. the default of 0 went into the box on the prompt where the user can input a response. I entered a 3 and a 4 so the result in ans is 12.
It writes the literal followed by the content of ans.
it concatenates the 3 and the 4 I entered and shows 34 it concatenates the 3 and the 4 I entered and shows 34. If I convert firstnum to a number using either parseFloat (which produces a floating number that can have decimals) or parseInt (which produces an integer number). Then I convert secondnum. Since JavaScript now knows they are numbers, it does the add and I see the answer of 7. the parenthesis. This should say parseInt.
Notice that the things I want to do if the if is true are within { } and the things I want to do with the else are also within { }. I do not need an end if because I have contained the processes this way.
After I calculate ans, I write it outside the if.
This flowchart shows the change I want to make so it checks for a / and if it is not a / it assigns 0 to ans.
I entered a + and so 0 was assigned to ans.