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

1.Fill it with buttons, each containing a description indicating which question

ID: 3816191 • Letter: 1

Question

1.Fill it with buttons, each containing a description indicating which question it will answer.

Each button will answer only one of the questions (3A, 3B, 3C, 4A, 4B, 4C and 4D).

2.When the button is clicked a function is called one for each loop below and record your responses as a JS comment inside each of those functions you have just defined.

A.How many times does the following loop execute and why is the output not displayed on a single line?

for (var a = 0; a < 5; a++)

{

document. write (“Go Gamecocks!!<br>”);

}

B.What is written to the document by the following loop?

var k = 12;

while (k >= 7)

{     

document. write (k + "th item, “);

k = k - 1;

}

C.Explain how the following code works in your comment after defining a function that performs this task.

do

{

var userInput = prompt (“enter password:”, “type password here”);

}

while (userInput != “aAbBcC”)    

3.Write the JavaScript code for the following tasks. Each number in the output generated must be printed on a new line.

A.A for loop that loops 7 times and prints out: 0 1 2 3 4 5 6.

B.A while loop that loops 6 times and prints out: 2 4 6 8 10 12.

Hint: you can increment your iterator by more than just 1.

C.A do while loop that loops 5 times and prints out: 1 2 3 4 5.

D.A for loop that loops 7 times and prints out: 1 8 27 64 125 216 343.

Hint: use the Math.pow(x,3) method in the body of the loop.

<!DOCTYPE html>
<html>
<head>
   <meta charset="utf-8">
   <title>lab13</title>
   <script>
   function A(var a=0; a<5; a++){
       document.write("Go Gamecocks!!<br>");
       document.
   }
   /*The loop executes 5 times */
   function B(){
       Var k=12
       while(k>=7)
       document.write(k+"th item, ");
       k=k-1;
   }
   /*12th item*/
   function C(){
       do
       {
           var userInput=prompt ("enter password:", "type password here");
       }
       while (userInput != "aAbBcC")
   }
   /*This means that the user input is not equal to aAbBcC */
   function answer4A(){
       var output " "
       for (i=0; i<7;i++0){
           output+=i+" "
       }
       document.getElementById("parag").innerHTML=output
   }
   </script>
</head>
<body>
<input type="button" id="3A" value="3A">
<input type="button" id="3B" value="3B">
<input type="button" id="3C" value="3C">
<input type="button" id="4A" value="4A">
<input type="button" id="4B" value="4B">
<input type="button" id="4C" value="4C">
<input type="button" id="4D" value="4D">
<textarea cols="20" rows="5" id="ta1" name="tarea1"></textarea>

</body>
</html>

Explanation / Answer

3.A)

<!DOCTYPE html>
<html>
<body>
<p>A for loop that loops 7 times and prints out: 0 1 2 3 4 5 6.</p>
<button>3A</button>
<script type="text/javascript">
function A() {
    for(var a = 0; a < 7; a++){
       document.write(a + " ");
   }
}
</script>
</body>
</html>

3.B)

<!DOCTYPE html>
<html>
<body>
<p>A while loop that loops 6 times and prints out: 2 4 6 8 10 12.</p>
<button>3B</button>
<script type="text/javascript">
function B() {
    var num = 0;
    while(num < 12){
       num = num + 2;
       document.write(num + " ");
   }
}
</script>
</body>
</html>

3.C)

<!DOCTYPE html>
<html>
<body>
<p>A do while loop that loops 5 times and prints out: 1 2 3 4 5.</p>
<button>3C</button>
<script type="text/javascript">
function C() {
    num = 0;
    do{
        num = num + 1;
        document.write(num +" ");
    }
    while (num < 5);
}
</script>
</body>
</html>

3.D)

<!DOCTYPE html>
<html>
<body>
<p>A for loop that loops 7 times and prints out: 1 8 27 64 125 216 343.</p>
<button>3D</button>
<script type="text/javascript">
function D() {
    for(var a = 1; a < 8; a++){
       var x = Math.pow(a,3)
       document.write(x + " ");
    }
}
</script>
</body>
</html>