122. Exercise: Make A Keyless Car

변지영·2021년 12월 8일
0

file:exercise4.zip
// Make a keyless car!
// This car will only let you drive if you are over 18. Make it do the following:

//using prompt() and alert(), ask a user for their age.
// IF they say they are below 18, respond with:
// "Sorry, you are too young to drive this car. Powering off"

// IF they say they are 18, respond with:
// "Congratulations on your first year of driving. Enjoy the ride!"

// IF they say they are over 18, respond with:
// "Powering On. Enjoy the ride!"

my exercise.

var age = prompt("How old are you?");
if( age < 18 ){
alert("Sorry, you are too young to drive this car. Powering off");
}else if( age === 18 ){
alert("Congratulations on your first year of driving. Enjoy the ride!");
}else{
alert("Powering On. Enjoy the ride!");
}

solutions.

var age = prompt("What is your age?");

if (Number(age) < 18) {
alert("Sorry, you are too yound to drive this car. Powering off");
} else if (Number(age) > 18) {
alert("Powering On. Enjoy the ride!");
} else if (Number(age) === 18) {
alert("Congratulations on your first year of driving. Enjoy the ride!");
}

1개의 댓글

comment-user-thumbnail
2022년 4월 7일

Thx for this

답글 달기