Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.

Commit bf85948

Browse files
week2Exercises.js file is ready to use.
1 parent 22873f7 commit bf85948

File tree

1 file changed

+13
-44
lines changed

1 file changed

+13
-44
lines changed

mandatory/week2Exercises.js

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ and for multiples of '5' and '3' print "FizzBuzz".
77
//* this exercise is for practicing "Conditionals: if-without-else , for" and "Logical Operators" and also "Comparison : ==="!
88
*/
99
function fizzBuzz (number){
10-
if (number % 3 === 0 && number % 5 === 0) return "FizzBuzz";
11-
if (number % 3 === 0) return "Fizz";
12-
if (number % 5 === 0) return "Buzz";
13-
return number;
10+
1411
}
1512
console.log(fizzBuzz(1));
1613
console.log(fizzBuzz(3));
@@ -30,8 +27,7 @@ function fizzBuzz (number){
3027
complete function to check if user is acceptable or not acceptable (+18 years old is acceptable!):
3128
*/
3229
function isAcceptableUser(userAge,isLoggedIn){
33-
let isAcceptable = userAge>18 && isLoggedIn;
34-
return(isAcceptable);
30+
3531
}
3632
console.log(isAcceptableUser(21,true));
3733

@@ -40,13 +36,7 @@ function fizzBuzz (number){
4036
*/
4137

4238
function applyDiscount(totalPrice){
43-
let discountPercent;
44-
if (totalPrice>200) {
45-
discountPercent = 10;
46-
}else{
47-
discountPercent = 5;
48-
}
49-
return (totalPrice-(totalPrice*discountPercent)/100);
39+
5040
}
5141
applyDiscount(120);
5242
applyDiscount(280);
@@ -55,32 +45,23 @@ function fizzBuzz (number){
5545
complete function to print odd numbers between 1 to limitNumber with while loop:
5646
*/
5747
function printOddNumbers(limit){
58-
let i = 1;
59-
while(i<=limit){
60-
61-
if(i%2!==0){
62-
console.log(i);
63-
}
64-
i+=1;
65-
}
48+
6649
}
6750
printOddNumbers(10);
6851

6952
/*
7053
complete buyTwoGetTheCheapestFree Function: if user buy two items, cheapest item will be free!
7154
*/
7255
function buyTwoGetTheCheapestFree(price1,price2){
73-
if (price1>price2) return price1;
74-
return price2;
56+
7557
}
7658
buyTwoGetTheCheapestFree(700,500);
7759
/*
7860
a function that check if user selected a color apply that else apply default color:
7961
*/
8062
function productColor(selectedColor){
8163

82-
let defaulColor = "purple";
83-
return selectedColor||defaulColor;
64+
8465
}
8566
productColor("pink");
8667
productColor();
@@ -89,32 +70,20 @@ function fizzBuzz (number){
8970
complete function to print mood: happy/not happy.
9071
*/
9172
function mood(isHappy) {
92-
if (isHappy) {
93-
return 'I am happy';
94-
} else {
95-
return 'I am not happy';
96-
}
73+
9774
}
9875
/*
9976
complete function to determine if it is suitable for person to register based on his age!
77+
age < 12 --> "Too Young To Register",
78+
12 < age < 90 --> "You Can Register",
79+
age > 90 --> "You Don't Need To Register"
10080
*/
10181
function canRegister(age) {
102-
if (age<12){
103-
return "You Are Too Young To Register";
104-
}
105-
else if(age>12 && age<90){
106-
return "You Can Register";
107-
}
108-
else{
109-
return "You Don't Need To Register";
110-
}
82+
11183
}
11284

11385
function countReverse(num){
114-
while(num>0){
115-
console.log(num);
116-
num = num-1;
117-
}
86+
11887
}
11988
countReverse(20);
12089

@@ -137,7 +106,7 @@ function fizzBuzz (number){
137106
});
138107

139108
test("isAcceptableUser function retern user is allowed or not", () => {
140-
expect(isAcceptableUser(21,true)).toEqual(true,false);
109+
expect(isAcceptableUser(21,true)).toEqual(true);
141110
});
142111

143112
test("applyDiscount function retern price after discount", () => {

0 commit comments

Comments
 (0)