Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lulunac27a committed Apr 16, 2024
1 parent 3795986 commit 570a523
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions dice-game-webapp/src/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ class Main {
var appContent:js.html.DivElement = cast(Browser.document.getElementById("app"), js.html.DivElement);
var rollButton:js.html.ButtonElement = cast(Browser.document.getElementById("roll"), js.html.ButtonElement);
var diceInput:js.html.InputElement = cast(Browser.document.getElementById("dice"), js.html.InputElement);
rollButton.onclick = (event) -> {
var numberOfDice:Int = Std.parseInt(diceInput.value);
appContent.innerHTML = "";
var dice:Array<Int> = [];
rollButton.onclick = (event) -> { // when roll dice button is clicked
var numberOfDice:Int = Std.parseInt(diceInput.value); // get number of dice to roll
appContent.innerHTML = ""; // set app content to empty string
var dice:Array<Int> = []; // initialize dice array
for (i in 0...numberOfDice) {
dice[i] = Std.random(6) + 1;
dice[i] = Std.random(6) + 1; // roll the dice
var newDice:js.html.DivElement = cast(js.Browser.document.createElement("div"), js.html.DivElement);
newDice.id = 'dice-${i + 1}';
newDice.textContent = 'Dice ${i + 1}: ${dice[i]}';
appContent.appendChild(newDice);
newDice.id = 'dice-${i + 1}'; // set id to dice-number to make id's unique
newDice.textContent = 'Dice ${i + 1}: ${dice[i]}'; // set text to each die value
appContent.appendChild(newDice); // append dice values to app content
}
}
}
Expand Down

0 comments on commit 570a523

Please sign in to comment.