- The industry is always changing with better technologies, frameworks and resources. Not
- to worry, this course is constantly being updated and contains everything to become an
- amazing developer in this evolving world !
-
-
-
-
-
Our grateful students
-
-
-
-
-
- Carl Smith
-
for all levels of skill and experience.
-
-
-
-
-
- Nikola Buzadzija
-
I am very happy that i have the opportunity to contribute to this open source project! YEAAAHHHHH!!!!
-
-
-
-
-
- Jane Johnson
-
Fantastic instructor, great atmosphere during the course!
- Absolutely worth recommending!
-
-
-
-
-
-
-
+
+
+
+
+
+ Number Guessing Game
+
+
+
+
+
+
+
Number guessing game
+
Try and guess a random number between 1 and 100.
+
You have 10 attempts to guess the right number.
+
+
+
+
+
Previous Guesses:
+
Guesses Remaining: 10
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
\ No newline at end of file
diff --git a/script.js b/script.js
new file mode 100644
index 0000000..42b96b0
--- /dev/null
+++ b/script.js
@@ -0,0 +1,93 @@
+
+let randomNumber = parseInt(Math.random() * 100 + 1);
+
+const submit = document.querySelector('#subt');
+const userInput = document.querySelector('#guessField');
+const guessSlot = document.querySelector('.guesses');
+const remaining = document.querySelector('.lastResult');
+const lowOrHi = document.querySelector('.lowOrHi');
+const startOver = document.querySelector('.resultParas');
+
+const p = document.createElement('p');
+
+let prevGuess = [];
+let numGuess = 1;
+
+let playGame = true;
+
+if (playGame) {
+ submit.addEventListener('click', function (e) {
+ e.preventDefault();
+ const guess = parseInt(userInput.value);
+ console.log(guess);
+ validateGuess(guess);
+ });
+}
+
+function validateGuess(guess) {
+ if (isNaN(guess)) {
+ alert('PLease enter a valid number');
+ } else if (guess < 1) {
+ alert('PLease enter a number more than 1');
+ } else if (guess > 100) {
+ alert('PLease enter a number less than 100');
+ } else {
+ prevGuess.push(guess);
+ if (numGuess === 11) {
+ displayGuess(guess);
+ displayMessage(`Game Over. Random number was ${randomNumber}`);
+ endGame();
+ } else {
+ displayGuess(guess);
+ checkGuess(guess);
+ }
+ }
+}
+
+function checkGuess(guess) {
+ if (guess === randomNumber) {
+ displayMessage(`You guessed it right`);
+ endGame();
+ } else if (guess < randomNumber) {
+ displayMessage(`Number is TOOO low`);
+ } else if (guess > randomNumber) {
+ displayMessage(`Number is TOOO High`);
+ }
+}
+
+function displayGuess(guess) {
+ userInput.value = '';
+ guessSlot.innerHTML += `${guess}, `;
+ numGuess++;
+ remaining.innerHTML = `${11 - numGuess} `;
+}
+
+function displayMessage(message) {
+ lowOrHi.innerHTML = `