Download presentation
Presentation is loading. Please wait.
Published byAngelica McKinney Modified over 9 years ago
1
Daniel Gagnon’s Final Project Number Guessing Game Widget By: Daniel Gagnon
2
Number Guessing Game Widget This is a Widget program that was created to be a game. The program first picks a random number between 0 and 50. The player then tries to guess that number in the fewest number of tries. The program gives the player hints every time a number is guessed. After the correct number is guessed, the program tells the player how many tries it took. This is a Widget program that was created to be a game. The program first picks a random number between 0 and 50. The player then tries to guess that number in the fewest number of tries. The program gives the player hints every time a number is guessed. After the correct number is guessed, the program tells the player how many tries it took.
3
Interesting parts of code Random Number Generator Random Number Generator var number = random(0,50); var number = random(0,50); This line of code creates a varaible “number” and the actual random number. This code is important beacasuse it is the most important part of the game. If there were no random number the player would not have to guess to get the correct number. This line of code creates a varaible “number” and the actual random number. This code is important beacasuse it is the most important part of the game. If there were no random number the player would not have to guess to get the correct number.
4
Interesting Code cont. Counter Counter var counter; var counter;counter=0;counter++ The first line of code creates a variable that will be used as a counter. The second line of code sets the counter to zero. The third line of code adds one to the counter every time the function is run. This code is important becasuse it lets the player of the game know how many tries it took them to guess the correct number. The first line of code creates a variable that will be used as a counter. The second line of code sets the counter to zero. The third line of code adds one to the counter every time the function is run. This code is important becasuse it lets the player of the game know how many tries it took them to guess the correct number.
5
Interesting Code cont. Interworking of the Game Interworking of the Game function tryNumber(theNumber) { function tryNumber(theNumber) { if (the_number.data <number) alert("Guess Higher"); else if (the_number.data > number) alert("Guess Lower"); } This is part of the function that runs the game. The first line establishes the function and the name of the function. The second line determines if the number the player guesses is less than the random number generated, while the third line determines if the player guesses greater than the random number. This function allows the program to tell the player if they need to guess a higher or lower number. This is part of the function that runs the game. The first line establishes the function and the name of the function. The second line determines if the number the player guesses is less than the random number generated, while the third line determines if the player guesses greater than the random number. This function allows the program to tell the player if they need to guess a higher or lower number.
6
What I Learned As the programmer of this game I learned that it is actually not too difficult to design a program and execute it as long as you have a drawn up plan. I made a drawing of how I wanted the program to look and work and then wrote it. This helped me a great deal. As the programmer of this game I learned that it is actually not too difficult to design a program and execute it as long as you have a drawn up plan. I made a drawing of how I wanted the program to look and work and then wrote it. This helped me a great deal. I first wrote this game to work on a website and not as a widget. This was a mistake. It is better to write the program only once and not have to rewrite it and figure everything out twice. I first wrote this game to work on a website and not as a widget. This was a mistake. It is better to write the program only once and not have to rewrite it and figure everything out twice. I also learned that a random number generator is a powerful tool and can be used for many applications. I also learned that a random number generator is a powerful tool and can be used for many applications.
7
Difficulties One of the difficulties that I ran into while creating this project was trying to create a function that helped the user determine if the number they guessed was too high or too low. I overcame this problem by trial and error. I tried different if, else if, and else statements until I figured out what worked and what didn’t. One of the difficulties that I ran into while creating this project was trying to create a function that helped the user determine if the number they guessed was too high or too low. I overcame this problem by trial and error. I tried different if, else if, and else statements until I figured out what worked and what didn’t. Another difficulity I had was trying to change my original program that I wrote for this project into a widget. I found that even though widgets use JavaScript you cannot just cut and paste your code into the widget. There is much more involved. Another difficulity I had was trying to change my original program that I wrote for this project into a widget. I found that even though widgets use JavaScript you cannot just cut and paste your code into the widget. There is much more involved.
8
Great Discoveries I don’t feel that I made any real new great discoveries for JavaScript or Widgets, but I do feel that I discovered Random Number Generators by myself. I don’t think we covered any random numbers in class so I felt accomplishment when I got my random number generator to work correctly with my game. I don’t feel that I made any real new great discoveries for JavaScript or Widgets, but I do feel that I discovered Random Number Generators by myself. I don’t think we covered any random numbers in class so I felt accomplishment when I got my random number generator to work correctly with my game.
9
Conclusion This project taught me a lot about programming. I learned how to set a goal for what I wanted my program to look like and do and I went and did it. I found that trial and error in programming is basically the only way to finalize a project to be sure it works 100% correctly. This project was challenging and fun for me and I felt I learned a lot for my first programming class. This project taught me a lot about programming. I learned how to set a goal for what I wanted my program to look like and do and I went and did it. I found that trial and error in programming is basically the only way to finalize a project to be sure it works 100% correctly. This project was challenging and fun for me and I felt I learned a lot for my first programming class.
10
Program and Slide Show Created by: Daniel Gagnon
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.