-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
108 lines (74 loc) · 1.92 KB
/
script.js
File metadata and controls
108 lines (74 loc) · 1.92 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
// Question 1
// Declaring a Variable
let number = 8;
// Check if number is Odd or Even
// The % is the modular operator here.
if (number % 2 === 0) {
console.log(number + " is even.");
} else {
console.log(number + " is odd.");
}
// Question 2
// Declaring Age
let age = 21;
// Check if user is eligible to vote
if (age >= 17) {
console.log("You are eligible to vote");
} else {
console.log("You are not eligible to vote");
}
// Question 3
// Grade Calculator
let score = 50;
// Prints A when score is higher than 70
if (score >= 70) {
console.log("Grade A");
// Prints B when score is higher than 60
} else if(score >= 60) {
console.log("Grade B");
// Prints C when score is higher than 50
} else if (score >= 50) {
console.log("Grade C");
// Prints Fail when score is lower than 50
} else if(score <50) {
console.log("Fail");
}
// Question 4
// Declaring Variable for username and password
let username = "admin";
let password = "1234a";
if(username === "admin" && password === "12344a"){
console.log("Log in Successful")
} else {
console.log("Invalid Credentials")
}
// OR
// Stored Credentials
let userName = "Peter";
let passWord = "1234ab";
// Credentials to check
let inputUsername = "Peter";
let inputpassWord = "1234ab";
if(inputUsername === userName && inputpassWord === passWord ){
console.log("Log in Successful")
} else {
console.log("Invalid Credentials")
}
// Question 5
// Profuct Discount Calculator
let product = {
name: "Laptop",
price: 20000,
isMember: true
};
// Final price for members is different from non members
// variable is declared without value because we don't know yet
let finalPrice;
// Apply discount rule
if(product.isMember){
finalPrice = product.price * 0.9; //10% discount
} else {
finalPrice = product.price;
}
console.log("Product:", product.name);
console.log("Final Price:", finalPrice);