Download presentation
Presentation is loading. Please wait.
1
Introduction to Programming
JAVASCRIPT Introduction to Programming
2
Javascript
3
Javascript
4
Javascript
5
Javascript
6
Javascript
7
Javascript
8
Javascript <html> <head> <title>My Web Page</title> <script type="text/javascript"> alert('hello world!'); </script> </head>
9
Javascript <html> <head> <title>My Web Page</title> <script type="text/javascript" src="navigation.js"></script> </head>
10
Javascript
11
Javascript
12
Javascript
13
Javascript
14
Javascript
15
Javascript
16
Javascript
17
Javascript
18
Javascript
19
Javascript
20
Javascript <script type="text/javascript"> var firstName = 'Cookie'; var lastName = 'Monster'; document.write('<p>'); document.write(firstName + ' ' + lastName); document.write('</p>'); </script>
21
Javascript <script type="text/javascript"> var name = prompt('What is your name?', ''); document.write('<p>Welcome ' + name + '</p>'); </script>
22
Javascript
23
Javascript Creating an Array To create and store items in an array, you first declare the array’s name (just as you would a variable) and then supply a list of comma separated values: each value represents one item in the list. To indicate an array, you put the list of items between opening and closing brackets—[ ]. var days = ['Mon', 'Tues', 'Wed', 'Thurs', 'Fri', 'Sat', 'Sun']; The brackets—[ ]—are very important. You can create an empty array without any elements like this: var playList = [];
24
Javascript <script type="text/javascript"> var days = ['Mon', 'Tues', 'Wed', 'Thurs', 'Fri', 'Sat', 'Sun']; alert(days[0]); var i = 4; //alert(days[i]); </script>
25
Javascript
26
Javascript <script type="text/javascript"> var properties = ['red', '14px', 'Arial']; properties[3] = 'bold'; properties[properties.length] = 'italic'; properties.push('bold'); properties.push('bold', 'italic', 'underlined'); properties.unshift('12px'); for(i=0;i<properties.length;i++) { document.write(properties[i]); document.write('</br>'); } </script>
27
Javascript
28
Javascript
29
Javascript
30
Javascript
31
Javascript
32
Adding Logic if ( condition ) { // some action happens here }
if (score > 100) { alert('You won!'); if (answer == 31) { alert('Correct. Saturn has 31 moons.');
33
Adding Logic
34
Adding Logic
35
Adding Logic if (condition) { // write what happens } else if (condition2) { } else { }
36
Adding Logic <script type="text/javascript"> var num= prompt(‘Enter a number', ‘60'); if (num >= 50) { alert(‘Thanks.'); } </script>
37
Adding Logic var fridayCash = prompt('How much money can you spend?', ''); if (fridayCash >= 50) { alert('You should go out to a dinner and a movie.'); } else if (fridayCash >= 35) { alert('You should go out to a fine meal.'); } else if (fridayCash >= 12) { alert('You should go see a movie.'); } else { alert('Looks like you'll be watching TV.'); }
38
Adding Logic Logical AND if (a < 10 && a > 1) { alert("The value " + a + " is between 1 and 10"); } Logical OR if (key == 'n' || key == 'N') { //move to the next photo Logical NOT if (! valid) { //print errors and don't submit form}
39
Adding Logic if (dayOfWeek == 'Friday') {
var fridayCash = prompt('How much money can you spend?', ''); if (fridayCash >= 50) { alert('You should go out to a dinner and a movie.'); } else if (fridayCash >= 35) { alert('You should go out to a fine meal.'); } else if (fridayCash >= 12) { alert('You should go see a movie.'); } else { alert('Looks like you'll be watching TV.'); }
40
Adding Logic
41
Adding Logic while (condition) { // javascript to repeat }
42
Adding Logic var num = 1; while (num <= 5) { document.write('Number ' + num + '<br>'); num = num + 1; } document.write('Number 1 <br>'); document.write('Number 2 <br>'); document.write('Number 3 <br>'); document.write('Number 4 <br>'); document.write('Number 5 <br>');
43
Adding Logic
44
Adding Logic
45
Adding Logic var num = 6; do{ document.write('Number ' + num + '<br>'); num = num + 1; } while (num <= 5) while (num <= 5) { }
46
Adding Logic
47
Introduction to Programming
JAVASCRIPT Introduction to Programming
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.