CSC 160 - Computer Programming for Non-majors

Assignment #8: Tracing a program with a while loop.

Due Tuesday, November 23, 2010

Below you will find a program that appeared on the last quiz. Run the program and determine its output. Also, determine what the final values are for all three variables.

<html>
  <body>
    <script type="text/javascript">
      var x, y, z;

      x = 0;
      y = 5;

      for (x = 1;  x <= y;  x++)	{
        z = x + y;
        if (z < 7)
          alert("The answer is " + z);
        else
          alert("Our value " + z);
      }
    </script>
  </body>
</html>

[Back to the Lab Assignment List]