Download presentation
Presentation is loading. Please wait.
Published byRosa Potter Modified over 6 years ago
1
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.
2
The first program writes on the document and also brings up a pop up that says Hello World!
3
Note the semi-colon at the end of each line.
4
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.
5
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.
6
It writes the literal followed by the content of ans.
7
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.
10
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.
11
After I calculate ans, I write it outside the if.
13
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.
15
I entered a + and so 0 was assigned to ans.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.