Presentation is loading. Please wait.

Presentation is loading. Please wait.

This is an introduction to JavaScript using the examples found at the CIS17 website. In previous examples I specified language = Javascript, instead of.

Similar presentations


Presentation on theme: "This is an introduction to JavaScript using the examples found at the CIS17 website. In previous examples I specified language = Javascript, instead of."— Presentation transcript:

1 This is an introduction to JavaScript using the examples found at the CIS17 website.
In previous examples I specified language = Javascript, instead of type = text/Javascript. JavaScript is the default script. In these examples, I embedded the script in the html tags without using the usual html head, title, body etc. This is workable, but I would change this format to include more html in a more professional version.

2 When I define the variables, I assign them an initial value.
Note that as I process, I take in user input and change the values in the memory variables. I also calculate an answer and change the value in that variable.

3 When I save this code, I save it with a .html or a .htm extension.

4 The plus sign can mean add or it can mean concatenate.
In this example, firstnum + secondnum involved concatenating the two together as one and since I entered 4, 5 the result was the concatenating of those two numbers and I got 45.

5 One way to make sure it adds is to convert the variables firstnum and secondnum to integers using parseInt(variable name). Then it is clear that you should be adding so the + does the arithmetic.

6 The comma can be used to separate fields
The comma can be used to separate fields. You can also use the concatenate + as you will see in future examples.

7 The = is the assignment sign which signs the value on the right to the variable name on the left. When you want to do comparisons in an IF statement, you use the == to ask if two variables or literals are equal.

8 Note that if you enter an a then a divide will be done
Note that if you enter an a then a divide will be done. Because I am checking to see if it is equal to * - it it is not equal to * then it will take the else and ot the divide.

9 Now, I have changed the code so that in the else I check to see if it was a /. If it is the / I do the divide, else I assign 0 to ans.

10 Now when I enter an a I will take the first else and then the second else and I will assign 0 to ans so I will display The answer is 0.

11 When a loop is done, you drop to the statement below the loop.
This is a while loop that checks before entering the loop.

12 This is a do loop with the condition checked in the while at the end of the loop. In this loop the statements inside will be executed at least once.

13 Interesting...

14


Download ppt "This is an introduction to JavaScript using the examples found at the CIS17 website. In previous examples I specified language = Javascript, instead of."

Similar presentations


Ads by Google