This repository has been archived by the owner on Oct 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
day1note.js
93 lines (88 loc) · 2.09 KB
/
day1note.js
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
// 1) Variable - (String)
var name = "Rajaruban";
console.log(name);
// String operation
var message = "Hello "+name;
console.log(message);
// 2) Variable number
var a = 10;
var b = 3;
var sum = a + b;
console.log(sum);
// Number operation
var minus = a - b;
console.log(minus);
var product = a * b;
console.log(product);
var division = a / b;
console.log(division);
var modulo = a % b;
console.log(modulo);
// Boolean
var hungry = true;
var diet = false;
// or & and
console.log(hungry && diet); // AND- both of it need to be true for it to be true...
console.log(hungry || diet); // OR- one of it need to be true for it to be true...
console.log(!hungry); // The reverse of the condition
// Condition (if else)
var age = 15;
if (age < 18) {
console.log("You cannot watch the movie");
}
else {
console.log("You may watch the movie");
}
if (age < 13) {
console.log("You cannot watch the movie");
}
else if (age < 18) {
console.log("You can watch the movie with parents");
}
else {
console.log("You may watch the movie");
}
// Even number validator
var number = 30;
if (number % 2 == 0) {
console.log(number+" is a even number");
}
else {
console.log(number+" is an odd number");
}
//Ticket price condition
var ticPrice = 100;
var age = 45;
if (age < 18 && age > 66) {
var price=ticPrice*0.5;
console.log("Ticket price is RM"+price);
}
else if (age > 18 && age < 40) {
var price=ticPrice;
console.log("Ticket price is RM"+price);
}
else {
console.log("Ticket price is RM"+ ticPrice * 0.75);
}
// For loop = repeat 10 times..
//from... 0 until 10; each iteration add by one
for (var i = 0; i < 10 ; i++){
// show the number
console.log(i);
}
//from... 10 until 0... each iteration i will minus by one
for (var i = 10; i > 0; i--){
// show the number
console.log(i);
}
//from... 0 until 10... each iteration add by two
for (var i = 1; i < 10; i+=2){
console.log(i);
}
// Multiplication table generator
var multiplier = 4;
var lines = 15;
// in this example <= smaller or equals to 15(until including 15)
for (var i = 1 ; i <= lines ; i++){
console.log(i+ " x "+multiplier+" = "+i*multiplier);
}