CSC 160 - Computer Programming for Non-majors

Assignment #7: Tracing a program with a for 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 = 12, y = 6, z = 0;

      while (x > y)	{
        z++;
        x = x - z;
        alert("X = " + x);
      }

      alert("X = " + x);

    </script>
  </body>
</html>

[Back to the Lab Assignment List]