44 1. the user should be 18 or older
55 2. the user must be logged in
66*/
7- function isAcceptableUser ( userAge , isLoggedIn ) { }
8-
7+ function isAcceptableUser ( userAge , isLoggedIn ) {
8+
9+ if ( userAge >= 18 && isLoggedIn === true ) {
10+ return true ;
11+ } else if ( userAge > 18 && isLoggedIn === true ) {
12+ return false ;
13+ } else {
14+ return false ;
15+ }
16+ }
917/*
1018 Complete the function to apply discount percent based on how much is totalPrice in user cart.
1119 - When the total price is greater than 200, a 10% discount should be applied
@@ -15,26 +23,55 @@ function isAcceptableUser(userAge, isLoggedIn) {}
1523 is applieds and 142.5 should be returned)
1624*/
1725
18- function applyDiscount ( totalPrice ) { }
26+ function applyDiscount ( totalPrice ) {
27+ if ( totalPrice > 200 ) {
28+ return totalPrice * 0.9 ;
29+ } else if ( totalPrice < 200 ) {
30+ return totalPrice * 0.95 ;
31+ }
32+ }
1933
2034/*
2135 Complete the function to print to the console the odd numbers between 1 and limit (use a while loop):
2236 */
23- function printOddNumbers ( limit ) { }
37+ function printOddNumbers ( limit ) {
38+ for ( let i = 1 ; i <= limit ; i ++ ) {
39+ if ( i % 2 === 1 ) {
40+ console . log ( i ) ;
41+ }
42+ }
43+ }
2444
2545/*
2646 Complete the buyTwoGetTheCheapestFree function: if user buys two items, the cheapest item will be free!
2747 The function should return the price to be paid once the discount is applied.
2848*/
29- function buyTwoGetTheCheapestFree ( price1 , price2 ) { }
49+ function buyTwoGetTheCheapestFree ( price1 , price2 ) {
50+ if ( price1 <= 0 || price2 <= 0 ) {
51+ return "Invalid prices. Prices must be more than 0." ;
52+ }
53+ if ( price1 >= price2 ) {
54+ return price1 ;
55+ } else {
56+ return price2 ;
57+ }
58+ }
3059
3160/*
3261 Complete the function to determine if it is suitable for a person to register based on their age!
3362 - if the person is 12 or younger it should return "You Are Too Young To Register"
3463 - if the person is older than 12 and younger than 90 it should return "You Can Register"
3564 - if the person is 90 or older it should return "You Don't Need To Register"
3665*/
37- function canRegister ( age ) { }
66+ function canRegister ( age ) {
67+ if ( age <= 12 ) {
68+ return "You Are Too Young To Register"
69+ } else if ( age > 12 && age < 90 ) {
70+ return "You Can Register"
71+ } else if ( age >= 90 ) {
72+ return "You Don't Need To Register"
73+ }
74+ }
3875
3976/*
4077 Complete the function so that it prints out to the console numbers in reverse order starting at
@@ -45,7 +82,11 @@ function canRegister(age) {}
4582 )
4683*/
4784
48- function countReverse ( number ) { }
85+ function countReverse ( number ) {
86+ for ( let i = number ; i >= 1 ; i -- ) {
87+ console . log ( i ) ;
88+ }
89+ }
4990
5091/* ======= TESTS - DO NOT MODIFY ===== */
5192
0 commit comments