Skip to content

Commit

Permalink
Add commas for numeric format in JavaScript web application
Browse files Browse the repository at this point in the history
  • Loading branch information
lulunac27a committed Apr 19, 2024
1 parent 82028f2 commit 880cab6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions dice-game-webapp/src/Main.hx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import js.lib.intl.NumberFormat;
import js.Browser;
import js.html.*;

Expand All @@ -16,10 +17,10 @@ class Main {
sum += dice[i]; // add die value to sum
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
newDice.textContent = 'Dice ${new NumberFormat().format(i + 1)}: ${dice[i]}'; // set text to each die value
appContent.appendChild(newDice); // append dice values to app content
}
appContent.innerHTML += '\nSum of dice: ${sum}'; // print sum of all dice and append to app content
appContent.innerHTML += '\nSum of dice: ${new NumberFormat().format(sum)}'; // print sum of all dice and append to app content
}
}
}

0 comments on commit 880cab6

Please sign in to comment.