File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // Question# 1
2+ // Declare a variable called age & assign to it your age. Show
3+ // your age in an alert box.
4+
5+ var age = 5 ;
6+ alert ( "I am" + " " + age + " " + "years old." ) ;
7+ console . log ( "I am" + " " + age + " " + "years old." ) ;
8+
9+ // Question# 2
10+ // Declare & initialize a variable to keep track of how many
11+ // times a visitor has visited a web page. Show his/her
12+ // number of visits on your web page. For example: “You
13+ // have visited this site N times”.
14+
15+ var visit_count ;
16+ visit_count = 10 ;
17+ alert ( "You have visited this site" + " " + visit_count + " " + "times." ) ;
18+ console . log ( "You have visited this site" + " " + visit_count + " " + "times." ) ;
19+
20+ // Question# 3
21+ // Declare a variable called birthYear & assign to it your
22+ // birth year. Show the following message in your browser:
23+
24+ var birth_year = 2015 ;
25+ document . write ( "My birth year is" + " " + birth_year + "<br/>" ) ;
26+ document . write (
27+ "Data type of my declared variable is number" + "<br/>"
28+ ) ;
29+
30+ // Question# 4
31+ // A visitor visits an online clothing store
32+ // www.xyzClothing.com . Write a script to store in variables
33+ // the following information:
34+ // b. Product title
35+ // c. Quantity i.e. how many products a visitor wants to
36+ // order
37+ // Show the following message in your browser: “John
38+ // Doe ordered 5 T-shirt(s) on XYZ Clothing store”.
39+
40+ var product_name = "T-Shirts" ;
41+ var quantity = 5 ;
42+ var visitor_name = "John Doe" ;
43+
44+ document . write ( `${ visitor_name } ordered ${ quantity } ${ product_name } on XYZ Clothing store` ) ;
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Chapter 3 Task | VARIABLES FOR NUMBERS </ title >
7+ </ head >
8+ < body >
9+ < script src ="app.js "> </ script >
10+ </ body >
11+ </ html >
Original file line number Diff line number Diff line change 33< head >
44 < meta charset ="UTF-8 ">
55 < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6- < title > VARIABLES FOR NUMBERS </ title >
6+ < title > Chapter 4 Task | VARIABLE NAMES: LEGAL & ILLEGAL </ title >
77</ head >
88< body >
99 < script src ="script.js "> </ script >
Original file line number Diff line number Diff line change 11// Question# 1
2- // Declare a variable called age & assign to it your age. Show
3- // your age in an alert box.
4-
5- var age = 5 ;
6- alert ( "I am" + " " + age + " " + "years old." ) ;
7- console . log ( "I am" + " " + age + " " + "years old." ) ;
8-
9- // Question# 2
10- // Declare & initialize a variable to keep track of how many
11- // times a visitor has visited a web page. Show his/her
12- // number of visits on your web page. For example: “You
13- // have visited this site N times”.
14-
15- var visit_count ;
16- visit_count = 10 ;
17- alert ( "You have visited this site" + " " + visit_count + " " + "times." ) ;
18- console . log ( "You have visited this site" + " " + visit_count + " " + "times." ) ;
19-
20- // Question# 3
21- // Declare a variable called birthYear & assign to it your
22- // birth year. Show the following message in your browser:
23-
24- var birth_year = 2015 ;
25- document . write ( "My birth year is" + " " + birth_year + "<br/>" ) ;
26- document . write (
27- "Data type of my declared variable is number" + "<br/>" + "<br/>"
28- ) ;
29-
30- // Question# 4
312// Declare 3 variables in one statement.
323var age ;
334var year ;
345var date ;
35-
36- // Question# 5
6+ // Question# 2
377// Declare 5 legal & 5 illegal variable names.
388// ==============================================
399// 5 Legal Variable name
@@ -50,7 +20,7 @@ var $person_name;
5020// var class; //reserved key is not being used because it has already been reserved and cannot used as variable it throws error.
5121// var car*name; //special characters cannot be used between variable but $ sign can be used.
5222
53- // Question# 6
23+ // Question# 3
5424// Display this in your browser
5525// a) A heading stating “Rules for naming JS variables”
5626var rules_for_JS = "Rules for naming JS variables" + "<br/>" + "<br/>" ;
You can’t perform that action at this time.
0 commit comments