Programs


Programs & Programming notes | PDF

Audio Quick Review (5:46)


Example Program

Here is an example guessing game program.  The number to be guessed is 631.  It is written in Javascript.  Javascript is a simple language used to create web pages.

 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

// write text in the web page document
// <BR> means new line
document.write("GUESSING GAME<BR>") 

// store number in variable called sekrit
var sekrit = 631

// prompt function knows 
// how to get input from user
// whatever it gets, store in variable guess
var guess = prompt("guess the number", "0")

// loop repeats indented lines inside { }
// as long as guess is not equal to sekrit 
while (guess != sekrit) {
	// if guess is too big, 
	// say so and ask again
	if(guess > sekrit) {
		guess = prompt(guess +" too high.", "0")

	// otherwise, must be too small, 
	// so say so and ask again
	} else {
		guess = prompt(guess +" too low.", "0")
	}
}

// since the loop ended, 
// they must have guessed right
document.write("YOU WIN!!!")

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

All lines beginning with // are explanatory comments, and are not run as part of the program.  (Everything between PROGRAM BEGINS and PROGRAM ENDS is the program, everything outside is there for the web page, not part of the program.)

 The W3Schools.com's Tryit Editor or JS.do allow you to run javascript programs and see their result.  Open one of these links (it will be easier if you do this in a new tab or window).

Copy and paste the program above into the box on the left side of the linked page, replacing what was there before

Then click the Submit/Run button, and the program's output will show up in the box on the right.  

You can make changes in the box on the left and run the program again with changes.  (The worst that can happen is that the program gets stuck asking for guesses forever and have to close the browser tab to get out of it.)


Review Questions

This is not work to be turned in for a grade.  They are however very similar to the questions on the Comprehension Quiz.

  1. What is the difference between a high level programming language and machine language?
  2. What is a variable?
  3. What is a comment?
  4. What job do compilers and interpreters both do?
  5. What is a compiler?
  6. What is an interpreter?
  7. What is an advantage  (for a user) of a program being in a compiled language?
  8. What is an advantage (for a user) of a program being in an interpreted language?
  9. What is an executable?
  10. What is a syntax error?
  11. What is a logic error?
  12. What do beta testers do?
  13. What do alpha testers do?
  14. What kind of errors (syntax or logic) do beta testers catch?
  15. What is an EULA? 
  16. What is open source software?
  17. What is shareware?