Guessing Game
Guessing Game 10/26/18
Guess a number 1 - 100
The program generates 10 random numbers 1 - 100. If your guess is 5 away from any of the
random
numbers
then you get 1 point, but if your guess is equal to a random number then you get 2 points.
This project was an assignment for class. It was my first time using JavaScript in a
practical
way.
Everything before this was mostly exercises to introduce us to new JS concepts and
practice.
Guessing Game 1.1
Download GuessingGame1.1.html
Changes
Uses form input instead of window prompt to get user input
Only Credits the "most correct" answer
Uses multiple paragraphs
Guessing Game 1.2
Download GuessingGame1.2.html
Changes
Uses loops instead of Ctrl+V
Has only 1 p id
Credits all correct answers, not just the "most correct" answer
Will only take number input
Last Edited - 10/26/18
Contributors - Mauricio
What I learned from making this game
- How to make/use loops and not copy and paste the same line of code 900 times.
- Format text output in JavaScript instead of make a new p id for everything.
- Comment in JavaScript effectively so I don't forget what everything does.
- Get user input with form input in HTML instead of a window prompt.
- Functions and arrays
Languages Used
HTML
JavaScript
Built With
Visual Studio Code
Background
Guessing Game 1.0 was the first practical program I made in class. When I first made it, it had a window
prompt
to collect user input, but it turns out Google Sites doesn't like pop ups. So "Guessing Game 1.1" you see
above
is not the original. When I first made it, I didn't know how to use loops, so I literally copied the same
code
10 times. It turns out I had the most sophisticated program in the class because no one else could read it,
including the teacher. The funny thing is, it didn't meet ONE of the assignment criteria, so I didn't get
full
credit. One of the requirements was "too high or too feedback", but that's literally impossible for my game
since there if multiple answers, or so I thought. The hardest part of making this program was getting the
user
input from the form input box to a variable. Up until then I had never really touched HTML so it was quite
the
challenge.
How it works
When you press the "Submit" button, a function called "GTN" runs.
First GTN generates 10 random numbers 1 - 100 and puts them into an array called "rNumb"
Then for each number in rNumb it calculates the difference between itself and whatever you might have
entered
into the input box and puts it into a new array called "minus".
Then if the smallest number is in rNumb is less than 5 your score goes up by one. But, if the smallest
number
is equal to 0 your score goes up by two. In other words, if one of the random numbers is within 5 of your
guess, you get 2 points, and if if it's equal to your guess you get 2 points.
Update the text information.
Feedback
When I first completed the assignment the program only generated 3 random numbers. Despite the margin of
error
of 5, it would still take around 8 attempts to get even 1 point, let alone getting 2 from getting
thecomplete
same number. So I increased the amount of random numbers to 5. Which at the time meant, copying and pasting
a
chunk of code 2 more times. Then I was told that the game was still to hard, so naturally I pasted the same
chunk 5 more times. In the end you win about 1 in 3 attempts.