Need help with my code for num guess game js

My javascript code on codepen wont run and i do not know what the error is
https://codepen.io/coderkoji/pen/poEZPeQ
can you please tell me why it wont run
thx

What do you mean by ‘won’t run’? The code is running when I click on your link.

when i run it the prompt wont show let me refresh it

nvm it works now thanks for helping me

1 Like

Im supposed to make a number guessing game where the computer makes a random number and then the player tries to guess it. It says like too big or too small or correct. The correct part of my code doesnt run when the user enters the right number. Can someone help me please

Firstly, welcome to the forums.

While we are primarily here to help people with their Free Code Camp progress, we are open to people on other paths, too. Some of what you are asking is pretty trivial in the Free Code Camp context, so you might find that if you’re not getting the instruction and material you need in your current studies, the FCC curriculum will really help you get started. At a modest guess I’d say investing a 4-5 hours working through the curriculum here will really pay off. You can find the curriculum at https://www.freecodecamp.org/learn.

With your current questions, we don’t have enough context to know what you already know or don’t know, so it is impossible to guide you without just telling you the answer (which we won’t do).

It is pretty typical on here for people to share a codepen / repl.it / jsfiddle example of what they have tried so that anyone helping has more of an idea of what help is actually helpful.

Please provide some example of what you’ve tried and I’m sure you’ll get more help.

Happy coding :slight_smile:

fine ill go to stackoverflow since no one here is helpful

I think this is the relevant part of your code:

while (guess != random || guess === random) {
	if (guess > random){
		alert("That is too big")
		guess = prompt("enter another guess ")
	}
	if (guess < random){
		alert("That is too small")
		guess = prompt("enter another guess ")
	}
	if (guess === random){
		alert("THATS CORRECT!")
	}
}

You have created an infinite loop.

while (guess != random || guess === random) {

guess will always either be equal to random or not equal to random, so your code will never stop looping.


Nobody said they wouldn’t help you. You made a post with minimal information, so we didn’t have enough information to be able to help until these two threads were combined.

if you give us enough info to help you, we are always happy to help!

if you want to go ask to stackoverflow, I hope you find someone able to help you!
There they have a pretty high standard for the questions, this guide may help you: https://stackoverflow.com/help/how-to-ask

Im supposed to make a number guessing game where the computer makes a random number and then the player tries to guess it. It says like too big or too small or correct. The correct part of my code doesnt run when the user enters the right number. Can someone help me please

https://codepen.io/coderkoji/pen/poEZPeQ

let random = Math.floor(Math.random() * 100) + 1;
let guess = prompt("enter your guess ")

while (guess != random || guess === random) { // You still have an infinite loop here
	if (guess > random){
		alert("That is too big")
		guess = prompt("enter another guess ")
	}
	if (guess < random){
		alert("That is too small")
		guess = prompt("enter another guess ")
	}
	if (guess === random){
		alert("THATS CORRECT!")
	}
}

people are trying to help you, please read their posts, consider what they have written, and answer them with more questions if you think what they have said is not useful for you

1 Like

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

1 Like