Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The snippets of JavaScript below contain syntax errors and/or logic errors. Iden

ID: 3571318 • Letter: T

Question

The snippets of JavaScript below contain syntax errors and/or logic errors. Identify the errors and insert your corrected code.

a. function main()

{

                var birthYear = Number(prompt("Enter your birth year"));

                while (birthYear < 0 or birthYear > 2020)

                {

                                console.log("The year entered was not greater than 0");

                                console.log(" or less than 2020. ");

                                birthYear = Number(prompt("Enter your birth year"));

                }

}

main();

b.function main()

{

                var score;

                do

                {

                                score = Number(prompt("Enter the score"));

                }

                while (score < 0 || score > 100)                

}

main();

c.function main()

{

var endProgram = prompt("Do you want to end the program, enter YES or NO");

while (endProgram != "NO" || endProgram != "YES")

{

                console.log("Invalid input");

                endProgram = prompt("Do you want to end the program, enter YES or NO");

               

}

}

main();

d.function main()

{

                var letterGrade = prompt("Enter a grade of S or U for the project");

                while (letterGrade != "S" and letterGrade != "U")

{

console.log("Valid letter grades are S or U");

letterGrade = prompt("Enter a grade of S or U for the project");

}

}

main();

e.function main()

{

var multiplier = prompt("Enter a value between 10 and 20");

if (multiplier < 10 || multiplier > 20)

{

                console.log("The value was not between 10 and 20");

multiplier = prompt("Enter a value between 10 and 20");

}

}

main();

Explanation / Answer

a. or is not a keyword here. So, should use the || there. Here is the code for you:

function main()
{
var birthYear = Number(prompt("Enter your birth year"));
while (birthYear < 0 || birthYear > 2020)
{
console.log("The year entered was not greater than 0");
console.log(" or less than 2020. ");
birthYear = Number(prompt("Enter your birth year"));
}
}
main();

b.

function main()
{
var score;
do
{
score = Number(prompt("Enter the score"));
}while (score < 0 || score > 100);
}
main();

c. The || should be replaced with &&.

function main()
{
var endProgram = prompt("Do you want to end the program, enter YES or NO");
while (endProgram != "NO" && endProgram != "YES")
{
console.log("Invalid input");
endProgram = prompt("Do you want to end the program, enter YES or NO");
}
}
main();

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote