app.ts 902 B

1234567891011121314151617181920212223242526272829303132
  1. function startGame() {
  2. // Starting a new game.
  3. let playerName: string = 'Audrey';
  4. logPlayer(playerName);
  5. const messagesElement: HTMLElement|null = document.getElementById('messages');
  6. if (messagesElement === null) {
  7. return;
  8. }
  9. messagesElement.innerText = 'Welcome to MultiMath! Starting a new game';
  10. console.log('Starting new game');
  11. }
  12. function logPlayer(name: string) {
  13. console.log(`New game starting for player: ${name}.`);
  14. }
  15. function arm(doc: HTMLDocument) {
  16. const startGameButton: HTMLElement|null = doc.getElementById('startGame');
  17. if (startGameButton) {
  18. startGameButton.addEventListener('click', startGame);
  19. }
  20. }
  21. arm(document);
  22. // Type assertions (not casting, more like in Go).
  23. let value: any = 42;
  24. let fixedString1: string = (<number>value).toFixed(2);
  25. let fixedString2: string = (value as number).toFixed(2);
  26. console.log(value, fixedString1, fixedString2);