-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol_flow.js
More file actions
91 lines (74 loc) · 2.58 KB
/
control_flow.js
File metadata and controls
91 lines (74 loc) · 2.58 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
// lets disscuss about control flow in JS
// There are different comparision operators in JS
/*
< // less than
> // greator than
<= // less than or equals to
>= // greator than or equals to
= // assignment operator
== // equals to
!= // not equals
=== strict equal (checks tha value and the data type of the numbers)
*/
/*
Temperature Converter:
Create a temperature converter function that takes a temperature in Celsius as input.
If the temperature is below freezing (0 degrees Celsius), return "It's freezing!"
If it's between 0 and 20 degrees, return "It's chilly." Otherwise, return "It's warm."
*/
const temp_Converter = (temperature) => {
if (temperature < 1) {
return `Its Freezing`;
} else if (temperature >= 1 && temperature <= 20) {
return `It's chilly`;
} else {
return `It's warm`;
}
}
// console.log(temp_Converter(21));
/*
Grade Calculator:
Write a program that calculates the grade based on a student's score.
If the score is above 90, return "A." If it's between 80 and 90, return "B."
If it's between 70 and 80, return "C." If it's below 70, return "F."
*/
const grading_Calculator = (score) => {
if (score > 90) {
return `A`
} else if (score >= 80) {
return `B`
} else if (score >= 70) {
return `C`
} else if (score < 70) {
return `F`
}
}
console.log(grading_Calculator(69));
/*
Login System:
Implement a simple login system. Ask the user to enter their username and password.
If the username and password match predefined values, log them in. If not, display an error message.
*/
const user_One = {
"user name": "Muhammad Shakir",
password : "Pakistan1234@"
}
const loginAuthenticator = (username, pas) => {
if (username === user_One["user name"] && pas === user_One.password) {
console.log("Logging In....");
} else {
console.log("The email or password you have entered seems to be incorrect");
}
}
loginAuthenticator("Muhammad Shakir", "Pakistan1234@"); // logging In....
loginAuthenticator("Muhammad Shakir", "Pakistan1234"); // The email or password you have entered seems to be incorrect
/*
Shopping Cart:
Write a function that calculates the total cost of items in a shopping cart.
If the total is above a certain threshold (e.g., $100), apply a discount of 10%. Otherwise, no discount is applied.
*/
const shoppingItemCostCalculator = (...items) => {
const total = items.reduce((acc, curr_Value) => acc + curr_Value, 0);
return total;
}
console.log(shoppingItemCostCalculator(999, 882, 222, 777, 1099)); // 3979