Number Guesser Challenge Project (JavaScript) question!

Hey guys, i am working on the number guesser challenge project on the functions part of the javascript course. I have completed it and my program is fully functioning but the only part that i do not understand is that none of the functions i created for this project ‘connnect’ with each other. They are all individial function with no coorelation to one another. I have completed a few other projects before doing this one and usually i create a ‘final’ function at the very end to merge all of the individual functions together to make my project work.

Why doesnt my code have a final function that merges all of my individual functions together to make my project function? Why does my project work even though all the indivual functions are not connect to one another. I have 4 different functions that represent a specific part of my project but there is no final function that connects them all together. am i missing something here?

Here is the completed version of the project (was given to us at the beginning of the project to give us an example of what our project is suppose to look like at the very end): https://s3.amazonaws.com/codecademy-content/PRO/independent-practice-projects/number-guesser/example/index.html

And here is my code:

let humanScore = 0;

let computerScore = 0;

let currentRoundNumber = 1;

// Write your code below:

function generateTarget() {

  return Math.floor(Math.random()*9);

}

function compareGuesses(humanGuess, computerGuess, targetNumber) {

  if (Math.abs(humanGuess - targetNumber) <= Math.abs(computerGuess - targetNumber)) {

    return true;

  } else if (Math.abs(humanGuess - targetNumber) > Math.abs(computerGuess - targetNumber)) {

    return false;

  }

}

function updateScore(winner) {

  if (winner === 'human') {

    humanScore +=1;

  } else if (winner==='computer') {

    computerScore +=1;

  }

}

function advanceRound() {

  currentRoundNumber +=1;

}

Hi! Welcome to the forums.

Can you retry pasting your code after hitting the </> (format) button. It’ll make it easier for people to see what’s happening and chime in :slight_smile:

1 Like

Yea this program doesn’t do anything yet. It’s just isolated functions without any invocation. If you compile it nothing will happen other than the definition of these functions…

So one thing you can do potentially: define a play() function that organizes the control flow of all of these and then invoke play().

Heres the thing though, i used the code above and my program fully worked

Here is the link to the assignment. there is no final function that combines everything together, yet, my code above works

https://www.codecademy.com/courses/introduction-to-javascript/projects/sleep-debt-calculator

Did you try running it in a plain environment?

I don’t have access to pro so I can’t see if they have any extensions to add to the program. I think there’s something else acting on your code.

A simple compile will have no effect. See this example:

@toastedpitabread & @net8268157128,

There is another JavaScript file (game.js) linked in the HTML file that handles calling the functions written by the learner in the project.

2 Likes