Skip to content

Commit

Permalink
Organize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
lulunac27a committed Apr 19, 2024
1 parent df669fd commit 82028f2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions dice-game-webapp/src/Main.hx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import js.Browser;
import js.html.*;

class Main {
static function 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);
var appContent:DivElement = cast(Browser.document.getElementById("app"), js.html.DivElement);
var rollButton:ButtonElement = cast(Browser.document.getElementById("roll"), js.html.ButtonElement);
var diceInput:InputElement = cast(Browser.document.getElementById("dice"), js.html.InputElement);
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
Expand All @@ -13,7 +14,7 @@ class Main {
for (i in 0...numberOfDice) {
dice[i] = Std.random(6) + 1; // roll the dice
sum += dice[i]; // add die value to sum
var newDice:js.html.DivElement = cast(js.Browser.document.createElement("div"), js.html.DivElement);
var newDice:js.html.DivElement = cast(Browser.document.createElement("div"), js.html.DivElement);
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 82028f2

Please sign in to comment.