31.8k views
14 votes
Critical thinking questions

this lesson showed you the general form of the syntax for a for loop in javascript:

for (initialize counter; condition; update counter) {

code block;}


what does each part do, and why is it necessary?

consider this javascript loop:

var new = 0;

for (i=3;i<=5;i++){

new=new+i;}


explain what the loop does and what the result of executing it will be.

most people are annoyed when they are asked to type in their password more than once. can you think of a way to perform data verification that does not require users to type in their password twice?

a website asks the user to enter his or her date of birth with the month first and then the day of the month. describe what you could do to prevent problems with the code if a user enters the information in the wrong order by placing the day of the month before the month.

your classmate is frustrated because the code that was designed to add up her five quiz grades is not working properly. what change would you suggest to your classmate based on this code?

for (i=1;i<=5;i++){

sum=0

sum=sum+i;}

1 Answer

6 votes

Answer:

1: A loop will continue running until the defined condition returns false . ... You can type js for , js while or js do while to get more info on any of these. ... initialization - Run before the first execution on the loop. ... But it can be used to decrement a counter too.

2: The loop increments the value of new while the loop condition is true. The end value of new is 3.

3: We could use some sort of finger recognition or face so they don’t have to type in their password.

4: give them a second chance for their date of birth.

5: sum = 0 must be before for loop. If inside for loop, it will keep resetting sum to 0 each iteration.

Step-by-step explanation:

User Dr Joe
by
4.7k points