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 trialNouh Ahmed
7,085 PointsUI.JS
Instead of declaring a variable to store the property of the dice object, i passed the the object as an argument and it work. So could someone tell the difference between these two approaches.
function printNumber(number) { var placeholder = document.getElementById("placeholder"); placeholder.innerHTML = number; }
var button = document.getElementById("button");
button.onclick = function() { // var result = dice.roll(); printNumber(dice.roll()); };
eodell
26,386 PointsI think that you've just found another approach to accomplish the same task. There's always multiple ways to get to the same place in development. I'm no expert but I can't see any drawbacks to your approach vice Andrew's. Great job.
1 Answer
Michael Braga
Full Stack JavaScript Techdegree Graduate 24,174 PointsThe result variable is there to understand the code more clearly, especially for new programmers:
button.onclick = function() {
var result = dice.roll();
printNumber(result);
}
Your approach is completely valid as well. You just don't create a variable and get straight to the point :)
button.onclick = function() {
printNumber(dice.roll());
}
Nouh Ahmed
7,085 PointsNouh Ahmed
7,085 Pointsi commented out the variable declaration part and passed the dice.roll() as an argument for the printNumber function.