1234567891011121314151617181920212223242526272829303132 |
- function startGame() {
- // Starting a new game.
- let playerName: string = 'Audrey';
- logPlayer(playerName);
- const messagesElement: HTMLElement|null = document.getElementById('messages');
- if (messagesElement === null) {
- return;
- }
- messagesElement.innerText = 'Welcome to MultiMath! Starting a new game';
- console.log('Starting new game');
- }
- function logPlayer(name: string) {
- console.log(`New game starting for player: ${name}.`);
- }
- function arm(doc: HTMLDocument) {
- const startGameButton: HTMLElement|null = doc.getElementById('startGame');
- if (startGameButton) {
- startGameButton.addEventListener('click', startGame);
- }
- }
- arm(document);
- // Type assertions (not casting, more like in Go).
- let value: any = 42;
- let fixedString1: string = (<number>value).toFixed(2);
- let fixedString2: string = (value as number).toFixed(2);
- console.log(value, fixedString1, fixedString2);
|