Programs

Classwork :

Include all answers to all parts in one Word document.  Remember to clearly label and spell-check your answers.


Part A

  1. What is the difference between a syntax error and a logic error?  Which kind are beta testers supposed to catch?
Part B

Select and copy this program (everything between the lines) written in JavaScript  that prints in a loop .

If you find that your web browser is showing you only the output rather than the program itself, try a different browser  


<html>
<body>
<script type="text/javascript">
<!-- ----PROGRAM BEGINS------- -->

// lines beginning with // are comments

// store text in variable
var message = " Hello World"

// variable for how many repetitions
var howmany = 5

// loop repeats indented lines 
// until howmany stops being greater than 0 
while (howmany > 0) {
	// print in document 
	// + adds words together, 
	// <br> moves down a line
	document.write(message + "<br>")

	// decrease howmany
	howmany = howmany - 1
}

<!-- ----PROGRAM ENDS--------- -->
</script>
</body>
</html>

 

Go to W3Schools.com's Tryit Editor or JS.do .

Replace all the text in the box on the left with the code you just copied.

Click the Run (or Run code) button to see what the program does.
Edit the program (in the left text box) so that

  1. instead of "Hello World" it prints out a different message of your choice
  2. instead of 5 times, it prints 25 times
  3. immediately above each line you edited to make these changes, add a new line with a comment saying what change you made

Once you have changed the code and tested that it works by clicking the Run button again, copy your code (just from after the PROGRAM BEGINS line to before the PROGRAM ENDS line) into your Word document.  Also copy all of the output.