Codecademy Forums

Number guesser help

Now you should be able to pick the game.js in the opened file explorer -> js

You don’t need to edit anything in the game.js file for the project. You only have to write the functions described in the steps. From the instructions:

In this project, you’ll write four functions in script.js . We’ve provided some additional JavaScript code in game.js that will call your functions based on user interactions, but you don’t need to look at game.js and shouldn’t edit it if you want your project to work as intended

how do i get to the game.js file? i think that if i saw it it would help me understand this project better

i got into the inner workings of the game.js file and pressed save and this came up :
/home/ccuser/workspace/independent-practice-js-number-guesser/game.js:3
const humanGuessInput = document.getElementById(‘human-guess’);
^

ReferenceError: document is not defined
at Object. (/home/ccuser/workspace/independent-practice-js-number-guesser/game.js:3:25)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
at bootstrap_node.js:542:3

Since there are only three units covered up to this point, there is nothing to be gained by opening the game.js file. The instructions are enough to guide us through this project. Close the tab and forget it exists, except remember that that is the script that the SCT is running to control the flow of the game.

One doubts the author (and possibly the engineers) ever intended for us to see that script. It’s one thing to teach a kid about pellets and BB’s but quite another to explain munitions.

We’re still at the pellets and BB’s stage, so keep your station and stay on course.

To wit:

We’ve provided some additional JavaScript code in game.js that will call your functions based on user interactions, but you don’t need to look at game.js and shouldn’t edit it if you want your project to work as intended.


Finally got around to checking out this project, and can see now why my earlier, speculative answers were not of much use. My bad.

Below is my own take on the instructions just to prove that if we follow them the program will work. Your code will definitely look different, but if it conforms, it too should work.

spoiler
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;

// Write your code below:
const generateTarget = () => Math.floor(Math.random() * 10);
const compareGuesses = (h, c, t) => Math.abs(h - t) <= Math.abs(c - t);
const updateScore = w => {
  switch (w) {
    case 'computer': computerScore++; break;
    default: humanScore++;
  }
}
const advanceRound = () => {
  currentRoundNumber++;
}
1 Like

Consider also that we can reassign an object.

let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;

// Write your code below:
const floor = Math.floor;
const random = Math.random;
const abs = Math.abs;
const generateTarget = () => floor(random() * 10);
const compareGuesses = (h, c, t) => abs(h - t) <= abs(c - t)
const updateScore = w => {
  switch (w) {
    case 'computer': computerScore++; break;
    default: humanScore++;
  }
}
const advanceRound = () => {
  currentRoundNumber++;
}