In: Computer Science
Re-write all with proper code syntax and
conventions
Add a while loop that continues to ask the age until a
blank value is entered, or a user presses cancel.
let userage=prompt("enterage");
let userageindays=userage*365;
let userageinmonths=userage*12;
let useragein hours=userageindays*24
get useragein-minutes=userageinhours*60
let userageinseconds=userageinminutes*60;
if userage>=40 {
console.log("You are older than 40";
} else {
console.log("You are younger than 40");
}
switch (true) {
case (userage<5):
console.log("You are between 0 and 5");
break;
case (userage<10):
console.log("You are between 5 and 10");
break;
case (userage<20):
console.log("You are between 5 and 10");
break;
case (userage<10):
console.log("You are between 5 and 10");
break;
case (userage<20):
console.log("You are between 5 and 10");
break;
case (userage<30):
console.log("You are between 5 and 10");
case (userage<40):
console.log("You are between 5 and 10");
case (userage<50):
console.log("You are between 5 and 10");
case (userage<60):
console.log("You are between 5 and 10");
case (userage<70):
console.log("You are between 5 and 10");
case (userage<80):
console.log("You are between 5 and 10");
case (userage<90):
console.log("You are between 5 and 10");
case (userage<100):
console.log("You are between 5 and 10");
case (userage>=100):
console.log("Wow you are older than 100");
break;
}
console log(`You are %userageindays months old,
%userageinmonths days old, %userageinhours hours old,
%userageinminutes minutes old, and %userageinseconds seconds
old`);
Here is code:
while (1) {
let userAge = prompt("Enter Age");
if (userAge === null || userAge.length === 0)
break;
let userAgeInDays = userAge * 365;
let userAgeInMonths = userAge * 12;
let userAgeInHours = userAgeInDays * 24
let userAgeInMinutes = userAgeInHours * 60
let userAgeInSeconds = userAgeInMinutes * 60;
console.log("Enter age is : " + userAge);
if (userAge >= 40) {
console.log("You are older than 40");
} else {
console.log("You are younger than 40");
}
if (userAge < 5)
console.log("You are between 0 and 4");
else if (userAge < 10)
console.log("You are between 5 and 9");
else if (userAge < 20)
console.log("You are between 10 and 19");
else if (userAge < 30)
console.log("You are between 20 and 29");
else if (userAge < 40)
console.log("You are between 30 and 39");
else if (userAge < 50)
console.log("You are between 40 and 49");
else if (userAge < 60)
console.log("You are between 50 and 59");
else if (userAge < 70)
console.log("You are between 60 and 69");
else if (userAge < 80)
console.log("You are between 70 and 79");
else if (userAge < 90)
console.log("You are between 80 and 89");
else if (userAge < 100)
console.log("You are between 90 and 99");
else if (userAge >= 100)
console.log("Wow you are older than 100");
console.log(`You are ${userAgeInDays} months old, ${userAgeInMonths} days old, ${userAgeInHours} hours old, ${userAgeInMinutes} minutes old, and ${userAgeInSeconds} seconds old`);
}
Output: