Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

What's wrong with my code

/* Variable to store play button by id for event listener assignment below - You can ignore this */
const playBtn = document.querySelector('#play-btn');

/* Variables to store DOM elements that display player's scores - You'll use these variables in the event listener below */
const scoreOneElement = document.querySelector('#score-1');
const scoreTwoElement = document.querySelector('#score-2');

// YOUR CODE GOES HERE!!! Do the steps below to complete this challenge

// 1) Uncomment the array below
//const twelveSidedDie = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
const twelveSidedDie = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];

// 2) Create a function named diceRoll.  Give it a parameter called array — this goes in the parens.
player.stamina = 6 + DiceRoll("1d6")
msg ("Stamina: " + player.stamina)
  // 2a) Create a variable that uses `Math.ceil`, `Math.random` and the length of the array parameter
Array.from({length: 40}, () => Math.floor(Math.random() * 40));
  // NOTE: Introducing Functions video — https://teamtreehouse.com/library/introducing-functions-5
  // NOTE: Create a Random Number video — https://teamtreehouse.com/library/javascript-basics/working-with-numbers/create-a-random-number

  // 2b) `return` the random number variable
var foo = getRandomNumber(0, 40);
console.log(foo);

1 Answer

Steven Parker
Steven Parker
231,153 Points

As I mentioned in your previous question, this code is missing parts (including HTML) needed to work. If you're using a workspace, make a snapshot and post the link to it here. That will contain all the code as well as the testing environment to make it easy to replicate the issue.

A link to the course page you are working with would also be helpful.

Steven Parker
Steven Parker
231,153 Points

It looks like you reposted this as a separate question, see my answer there.