Conditions Assignment

The assignment

Choose one of the last four assignments (6-9 inclusive). Write the STA (and perhaps a sample code trace) in HTML. In a script, write the actual program on the same page. Although you do not have to turn them in, you may want to work on the earlier programs as well, as they are easier and will give you good practice. You might also want to implement some of the other programs besides the one you must turn in. There is no such thing as too much practice. You WILL see some of these algorithms later in the course (we will implement them in different languages) so it makes sense to know them all. We will give extra credit for submitting more than the minimum requirement.

Exercises

    OPTIONAL PRACTICE EXERCISES
  1. Write a password program. It should ask the user for a password, and if the user gets it right, congratulate her. If she gets it wrong, tell her so.
  2. Improve the password program so it repeats if the user gets the password incorrectly keep asking for the password until the user gets it right.
  3. Improve the above program so the user can get it wrong up to three times. If they do not get the password after three tries, exit the program.
  4. Write a simple quiz program that asks the user a math question, then evaluates the answer. If the user got it right, tell her so. If she got it wrong, give her another chance.
  5. Write a program that generates a multiplication table. Ask the user for a number, and show that number multiplied by 1 through 10.


    You MUST write at least one of these:
  6. Write a more complete multiplication table that shows all the values of 1-10 multiplied by each other in a table. HINT: you will need two for loops nested inside each other!! Use the \t (tab) and \n characters to format the table.
  7. Write a number guessing game. The computer will come up with a random integer between 1 and 100, and the user will make guesses about the number. After the user guesses, the computer will tell her whether she is too high, too low, or has hit the number. The program should keep track of the number of turns it took to guess the number.
  8. Write the same game as the last problem, but this time reverse the logic. The player will come up with the random number, and the program will guess, after which the player will tell the computer 'too high, too low, or just right'. Hint: think carefully about the smartest way to play the game as the user and analyze how you came to the numbers you guessed.
  9. Write a program that converts a number from decimal to binary. Ask the user for a base 10 number below 64, then use a loop to calculate the digits of binary. DO NOT use the automatic conversion feature built into Javascript (although you can use it to check your answers). Hint: Make the binary output a string value, and use the Math.pow() method inside a loop to determine whether each digit will be 0 or 1. Then concatenate the string digits together for the result.

© Andy Harris
Indiana University / Purdue University, Indianapolis
email: aharris@.cs.iupui.edu
homepage: http://www.cs.iupui.edu/~aharris