FAQ: Code Challenges: JavaScript Fundamentals - Fix The Broken Code


This community-built FAQ covers the “Fix The Broken Code” exercise from the lesson “Code Challenges: JavaScript Fundamentals”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

FAQs on the exercise Fix The Broken Code

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


Although my code below seems valid, I’m trying to use console.log() to figure out what each individual die actually is (as suggested in Hint); however, when I do that, I get “ReferenceError: die1 is not defined at Object.”. Any ideas why?


I suppose that something is wrong in test.js file.


hello !!! I wanted to ask a question…Why we are multiplying by 6 and then adding 1 ? why we are not multiplying by 7 straight away?


Sorry, i think I found out by myself. so, if the random number will be floored to 0 - it is not existing on the dice. By adding 1 we make it real. Do i think correct ??


Wouldn’t Math.ceiling work to round the numbers up to 1-6, then you can get rid of the +1? That’s what I tried and it didn’t accept it.


The ceiling of 0 is 0, so it will not be a viable option.

x = Math.ceiling(Math.random() * 6)

The solution set to the above is,

{ x | 0 <= x <= 6 }

as in,

{0, 1, 2, 3, 4, 5, 6}


x = Math.floor(Math.random() * 6 + 1)

has a solution set,

{ x | 0 < x <= 6 }

as in,

{1, 2, 3, 4, 5, 6}