Skip to content

Commit 6011e61

Browse files
committed
initializing Javascript course
1 parent d53b863 commit 6011e61

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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>VARIABLES FOR NUMBERS</title>
7+
</head>
8+
<body>
9+
<script src="script.js"></script>
10+
</body>
11+
</html>

script.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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/>" + "<br/>"
28+
);
29+
30+
// Question# 4
31+
// Declare 3 variables in one statement.
32+
var age;
33+
var year;
34+
var date;
35+
36+
// Question# 5
37+
// Declare 5 legal & 5 illegal variable names.
38+
// ==============================================
39+
// 5 Legal Variable name
40+
var firstName;
41+
var last_name;
42+
var Full$Name;
43+
var _birthDate;
44+
var $person_name;
45+
// ==============================================
46+
// 5 Illegal Variable name
47+
// var 1firstUser; // number can't be written in the first of variable name.
48+
// var &modelName; // symbols can't be used in teh starting of variable name.
49+
// var user id; //spaace is not allowed between varibale name it throws bugs.
50+
// var class; //reserved key is not being used because it has already been reserved and cannot used as variable it throws error.
51+
// var car*name; //special characters cannot be used between variable but $ sign can be used.
52+
53+
// Question# 6
54+
// Display this in your browser
55+
// a) A heading stating “Rules for naming JS variables”
56+
var rules_for_JS = "Rules for naming JS variables" + "<br/>" + "<br/>";
57+
document.write(rules_for_JS);
58+
59+
// b) Variable names can only contain ______, ______, ______ and ______. For example $my_1stVariable
60+
61+
var variable_rules =
62+
"Variable names can only contain _ , $ and number For example: $person_name1 " +
63+
"<br/>" +
64+
"<br/>";
65+
document.write(variable_rules);
66+
67+
// c) Variables must begin with a ______, ______ or _____. For example $name, _name or name
68+
var vari_start_with =
69+
"Variables must begin with a letter, _ or $. For example $person, _person or person" +
70+
"<br/>" +
71+
"<br/>";
72+
document.write(vari_start_with);
73+
74+
// d) Variable names are case _________
75+
var variable_cases = "Variable names are case sensitive " + "<br/>" + "<br/>";
76+
document.write(variable_cases);
77+
78+
// e) Variable names should not be JS _________
79+
var variable_name =
80+
"Variable names should not be JS keywords." + "<br/>" + "<br/>";
81+
document.write(variable_name);

0 commit comments

Comments
 (0)