-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript2.js
More file actions
160 lines (138 loc) · 4.33 KB
/
Copy pathscript2.js
File metadata and controls
160 lines (138 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//
// // Working with number
//
// // program One
var numberOfSecondsInMinute = 60;
var numberOfMinutesInHour = 60 ;
var numberOfHoursInDays = 24;
var numberOfDaysInWeek = 7;
var numberOfDaysInYear = 365;
var numberofDaysInMonth = 31;
var numberOfWeeksInYears = 52;
var secondsPerDay = numberOfSecondsInMinute * numberOfMinutesInHour * numberOfHoursInDays;
document.write('There are '+secondsPerDay+' seconds in a day');
// // Program 2
// // prompt() returns us the string varaible.
var htmlBadges = prompt("Please Enter the Number of html Badges you received ? ");
var cssBadges = prompt ("Please Enter the Number of css Badges you received");
var totalBadges = htmlBadges+cssBadges;
document.write("There are total "+ totalBadges + " you had got");
// // program 3
// // Using parseInt() to convert string to integer and correcting the program
//
// var htmlBadges = prompt("Please Enter the Number of html Badges you received ? ");
// var cssBadges = prompt ("Please Enter the Number of css Badges you received");
// var totalBadges = parseInt(htmlBadges) + parseInt(cssBadges);
// document.write("There are total "+ totalBadges + "Badges you had got");
//
// // Program 4
//
// // The Mad libs challenge presented
//
// // Let the player know how many questios are remained to be answer.
// var questions = 3;
var questiosLeft = '[' + questions + 'questionsLeft]';
var adjective = prompt("Please Enter the adjective"+ questiosLeft);
questions --;
questiosLeft = '[' + questions + 'questionsLeft]';
var verb = prompt("Please Enter the verb"+ questiosLeft);
questions --;
questiosLeft = '[' + questions + 'questionsLeft]';
var noun = prompt("Please Enter the noun "+ questiosLeft);
var sentence = "<h2> There was a "+adjective +" programmer";
sentence += " who wanted to use javascript to "+verb+ " the ";
sentence += noun;
document.write(sentence);
//
//
// //program statement 5
// //Generating Random number using javascript
//
// Use Math object to generate the random number .
//
// Math.random returns the number between 0 and 1
//
// Math.floor() and Math.ceil provides the decimal value to integer when you
// provides values to this methods
//
// Math.floor() rounds the value of to the lower side.
//
// Math.ceil() rounds the value to the upper side .
//
//
// //Program 5
//
// //Rolling the dice
//
var x = Math.floor(Math.random() * 6) + 1;
alert("you have rolled the number " + x);
//
//
// //Program 7
//
// //The random number challenge ---
//
//
//Generate a random number till the value input by user.
var userInput = parseInt(prompt("please Enter a value ?"));
var x = Math.floor(Math.random() * userInput) + 1;
alert("you have rolled the number " + x);
//Generate a random number till between two values generate by user.
// // program 8
//
var lower = parseInt(prompt("please Enter a starting value?"));
var upper = parseInt(prompt("please Enter a ending value?"));
var randomNumber = Math.floor(Math.random() * (upper - lower+1)) + lower;
alert("you have rolled the number " + randomNumber);
//
// //program 9
// Make one program with if statement , one with else statement and
// and came the case of uppercase.
var answer = prompt('What programming language is the name of your gem?');
if(answer.toUpperCase() === 'RUBY'){
document.write("<p> That's right </p>");
} else {
document.write("<p> Sorry , that's wrong .</p>")
}
//program 10
// Every number comes before alphabets , hence 90 < b will be true .
if("90" < "b"){
console.log("true");
}
if("3" == 3){
console.log("true");
}
if("3" === 3){
console.log("true");
}
else {
console.log(false)
}
if("" == 0){
console.log(true);
}
if("" === 0){
console.log(true);
}
else {
console.log(false);
}
//
// If you compare a number with a string with numeric literal, == allows that,
// but === doesn't allow that, because it not only checks the value but also
// type of two variable,if two variables are not of the same type "===" return
// false, while "==" return true.
// program 11
//console.log(a);
// console.log('apple' < 'bear')
// console.log(2 > 4)
// console.log(100 >= 100)
// console.log(3 < 2);
// console.log(-12 < 0)
// console.log('apple' < '12');
// console.log(3 === '3');
// console.log(3 == 3);
// console.log('' == 0 ); // true
// console.log(''=== 0); // false
// console.log('10'!== 10);//true
// console.log(-159 !== -159)