Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Why is this teacher showing us old 1998 programming?

I downloaded the following files for this video, the code did not match, it was very confusing on the old coding techniques used in the video until I had to do further research on the PROPER ways on making this dice to roll and get the number. Please review the proper code.

<div class="contentHolder"></div>
<button type="button" class="myButton">Roll Dice</button>
* {
  font-family: Helvetica, Arial, sans-serif;
  text-align: center;
}
button {
  background-color: rgb(82, 186, 179);
  border-radius: 6px;
  border: none;
  color: rgb(255, 255, 255);
  padding: 10px;
  text-transform: uppercase;
  width: 200px;
  cursor: pointer;
}
.contentHolder {
  height: 100px;
  width: 100px;
  padding: 50px;
  margin: 50px auto;
  border: 1px solid gray;
  border-radius: 10px;  
  font-size:80px;
}
function Dice(){
    this.sides = 6;
}   

Dice.prototype.roll = function (){
  var randomNumber = Math.floor(Math.random() * this.sides) + 1;
  return randomNumber;
}

Dice.prototype.printNumber = function (){
  var contentHolder = document.querySelector(".contentHolder");
  contentHolder.innerHTML = this.roll();
}


var myDice = new Dice();
var button = document.querySelector(".myButton");
button.addEventListener("click", myDice.printNumber.bind(myDice), false);

https://jsfiddle.net/4xfvk5oh/2/

1 Answer

Steven Parker
Steven Parker
220,937 Points

Since there's no subject tags or links to the course or teachers in your post, the staff may not see it.

To make sure any issues with the material reach the staff, try writing directly to Treehouse Support.