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: 3685216 • 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 should be represented with ||

so it is while ($birthYear < 0 || $birthYear > 2020)

b) error in while (score < 0 || score > 100)  

should be while ($score < 0 || $ score > 100)  

c) logical error in this statement

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

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

d)error in while (letterGrade != "S" and letterGrade != "U")

it should be while ($letterGrade != "S" and $letterGrade != "U")

e)if (multiplier < 10 || multiplier > 20)

should be if ($multiplier < 10 || $multiplier > 20)

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