Question

In: Computer Science

Re-write all with proper code syntax and conventions Add a while loop that continues to ask...

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`);

Solutions

Expert Solution

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:


Related Solutions

C++ while loop Exercise Write a program that continues to ask the user to enter any...
C++ while loop Exercise Write a program that continues to ask the user to enter any set of numbers, until the user enters the number -1. Then display the total sum of numbers entered and their average. (note that you need to define a counter that counts how many numbers so the average = (sum/n) where n is your counter total. #include <iostream> using namespace std; int main() { int number, n=0, sum=0; cout << "Enter a number to start...
Re-write following while loop into Java statements that use a Do-while loop. Your final code should...
Re-write following while loop into Java statements that use a Do-while loop. Your final code should result in the same output as the original code below. int total = 0; while(total<100) { System.out.println("you can still buy for"+(100-total)+"Dollars"); total=total+5; }
a) i) The following VHDL code contains erroneous syntax. Re write the code in its corrected...
a) i) The following VHDL code contains erroneous syntax. Re write the code in its corrected format onto your answer sheet. You may assume that din is a 16-bit vector and that the ld, lr and cl inputs are 1-bit wide. lp: process(clk) signal reg : std_logic_vector(15 downt begin if cl=’1’ then reg := (others:=’0’); else if clk=’1’ and clkevent then if ld=’1’ reg <= din; end if; if lr=’1’ then reg := reg(14 downto 0) & “0 else reg...
Write a program that uses a while loop with a priming read to ask the user...
Write a program that uses a while loop with a priming read to ask the user to input a set positive integers. As long as the user enters a number greater than -1, the program should accumulate the total, keep track of the number of numbers being entered and then calculate the average of the set of numbers after the user enters a -1. This is a sentinel controlled-loop. Here is what a sample run should look like: Enter the...
Open Average Test Scores while loop, comment out the while loop and add a for loop...
Open Average Test Scores while loop, comment out the while loop and add a for loop that averages 4 test scores. Code C# While loop code using System; class Program { static void Main() { int count = 0, total = 0, number;    while (count < 3) { Console.Write("Enter a number: "); number = Convert.ToInt32(Console.ReadLine()); total += number; count++; }    double average = total / 3.0; Console.Write("Average = " + average.ToString("####0.00")); } }
in java Write a while loop to ask the user to type number of hours(double) they...
in java Write a while loop to ask the user to type number of hours(double) they work per day. Calculate and print the salary for each valid input. If number of hours is greater than or equal to 0 and less than 5, then:  salary = numberofhours * 5, loop continues, the user can type another number If number of hours is greater or equal to 5, and less than 10, then: salary = numberofours * 8, loop continues, the user...
Hello, I Have create this code and Tried to add do while loop but it gives...
Hello, I Have create this code and Tried to add do while loop but it gives me the error in string answar; and the areas where I blod So cloud you please help me to do ( do while ) in this code. // Program objective: requires user to input the data, program runs through the data,calcualtes the quantity, chacks prices for each iteam intered,calautes the prices seperatly for each item, and calculates the amount due without tax, and then...
Code in python Write a while loop code where it always starts form 2. Then it...
Code in python Write a while loop code where it always starts form 2. Then it randomly chooses a number from 1-4. If the number 4 is hit then it will write “TP” if the number 1 is hit then it will write”SL”. It will rerun the program every time the numbers 1 and 5 are hit. The code should also output every single number that is randomly chosen. 2 of the same numbers can't be chosen back to back...
Write a while loop to ask the user to type number of hours(double) they work per...
Write a while loop to ask the user to type number of hours(double) they work per day. Calculate and print the salary for each valid input. If number of hours is greater than 0 and less than 5, then:  salary = numberofhours * 12, loop continues, the user can type another number If number of hours is greater or equal to 5, and less than 12, then: salary = numberofours * 14, loop continues, the user can type another number If...
Study the following code with a while-loop and convert it to a for-loop (fill in the...
Study the following code with a while-loop and convert it to a for-loop (fill in the blanks). int i=4, result=1; while(i>1) { result *= i; i--; } The following for-loop performs the same functionality: int result=1; for (__________ i=4; i _________1;____________) { result *= i; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT