I finished all the tasks - #12
Conversation
| // TODO: ADD YOUR CODE BELOW | ||
| let userAge=20 | ||
| let minDrivingAge=18 | ||
| if(userAge>minDrivingAge){console.log("the person is old enough to drive");} |
There was a problem hiding this comment.
Well done! Please pay attention to your code organization. When you write the block of code for the if statement, it's better to add it in the next line, not right next to the curly brackets. The same goes for the closing bracket. Like this:
if(userAge>minDrivingAge){
console.log("the person is old enough to drive");
}
| let userAge=20 | ||
| let minDrivingAge=18 | ||
| if(userAge>minDrivingAge){console.log("the person is old enough to drive");} | ||
| else{console.log("the person is not old enough to drive");} |
There was a problem hiding this comment.
Same here:
else{
console.log("the person is not old enough to drive");
}
| let userName="ameer" | ||
| let role="admin" | ||
| let username= prompt ('enter your name') | ||
| if (userName==username&&role=="admin"){console.log(` Hello ${userName} , and you have permission to access the restricted area.`);} |
There was a problem hiding this comment.
-
It's not recommended to use the same variable name with different cases like
usernameanduserNameas they refer to different values.
You can differentiate between which refers to which: use clear, concise names likeusernameandusernameInputorenteredUsername. -
Also, for the block of code within the curly brackets of the if statement, please write the block of code on the next line, not right next to the curly bracket.
This makes your code more organized and readable.
| - If the number is zero, print a message saying that it is zero. | ||
| ************************************************************************************************/ | ||
| // TODO: ADD YOUR CODE BELOW | ||
| let number=2 |
There was a problem hiding this comment.
You're initializing the number variable with a value of 2, but you should be asking the user to input the number. Therefore, you don't need to initialize number at the beginning.
| // TODO: ADD YOUR CODE BELOW | ||
| let number=2 | ||
| let asknumber=prompt("enter a number") | ||
| if(asknumber==0){console.log(`it is zero`);} |
There was a problem hiding this comment.
Please read the task description before jumping directly into the solution. 🙂
| - If the user is younger than 18, the program should calculate how many years are left until they turn 18 and print the message "You will be eligible to vote in X years", where X is the number of years left. | ||
| ************************************************************************************************/ | ||
| // TODO: ADD YOUR CODE BELOW | ||
| let userage=18 |
There was a problem hiding this comment.
The variable userage is assigned to 18. Instead, you should prompt the user to input their age and convert the input to an integer as mentioned in the description.
| // TODO: ADD YOUR CODE BELOW | ||
| let userage=18 | ||
| if (userage>=18) | ||
| if(confirm("press" )) console.log(`you press ok `); |
There was a problem hiding this comment.
The nested if-else statements are not properly structured. You need to use curly braces {} to define the block of code for each if-else condition.
The confirmation message within the confirm() function is missing. It should provide some context for the user to make a decision!
| let userage=18 | ||
| if (userage>=18) | ||
| if(confirm("press" )) console.log(`you press ok `); | ||
| else(console.log("Why did you waste my time then? 😀.")) |
There was a problem hiding this comment.
The block of code within the else statement should be wrapped with curly brackets {}, not parentheses. Like this:
else {console.log("Why did you waste my time then? 😀.") }
There's a missing calculation for the number of years left until the user turns 18 if they are younger than 18.
| case "Pisces":`(February 19 - March 20): | ||
| Horoscope: Your sensitivity and intuition are heightened today, Pisces. Pay attention to your dreams and emotions, as they may hold important messages for you. Take some time for self-reflection and introspection. | ||
| ` | ||
| default:console.log("Sorry, we do not have a horoscope for that sign."); } |
There was a problem hiding this comment.
Please organize your code better next time:
- Start the statement of each case in the switch case statement on the next line below the case keyword, not next to it.
- End the curly bracket below all the switch statements.
| break | ||
| default:console.log("Sorry, we do not have recommendations for that weather condition."); | ||
| ; | ||
| } |
There was a problem hiding this comment.
Please organize your code better next time:
- remove the extra spaces between line 89 and 90, and 93 and 95
No description provided.