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: 3679821 • 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()

{

            for(i = 0, i < 10, i++)

            {

            console.log("The value of i is " + i);

            }

}

main();

b. function main()

{

            var num;

            var keepLooping = 1;

            while (keepLooping = 1)

            {

          

                        keepLooping = Number(prompt("Enter 1 to repeat the loop"));

            }

}

main();

c. function main()

{

var loopNum;

loopNum = Number(prompt("Enter the number of times to loop"));

var ctr = 1;

console.log(“The even numbers in the range entered are: “);

do

{

console.log(ctr);

ctr = ctr + 2;

}

while (ctr <= loopNum)

}

main();

d. function main()

{

            ctr = 1;

            do while (ctr <= 10)

            {

                      console.log ("The value of ctr is " + ctr);

                        ctr = ctr + 1;

            }

}

main();

e. function main()

{

for (i=10; i > 0; i++)

{

console.log("i contains the value " + i);

i = i + 1;

}

}

main();

Explanation / Answer

a) function main()

{

            for(i = 0; i < 10; i++)

            {

            console.log("The value of i is " + i);

            }

}

main();

d. function main()

{

            ctr = 1;

            do {

                      console.log ("The value of ctr is " + ctr);

                        ctr = ctr + 1;

            } while (ctr <= 10)

}

e) function main()

{

for (i=10; i > 0; i++)

{

console.log("i contains the value " + i);

}

}

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