Browse Source

4.8: Using arrow functions with typed parameters.

Frederic G. MARAND 5 years ago
parent
commit
cd239a2797
1 changed files with 16 additions and 0 deletions
  1. 16 0
      app/app.ts

+ 16 - 0
app/app.ts

@@ -20,8 +20,18 @@ function getInputValue(elementId: string): string | undefined {
 }
 
 function postScore(score: number, playerName: string = 'MultiMath player'): void {
+  let logger: (value: string) => void;
+
+  if (score < 0) {
+    logger = logError;
+  }
+  else {
+    logger = logMessage;
+  }
+
   let scoreElement: HTMLElement | null = document.getElementById('postedScores');
   scoreElement!.innerText = `${score} - ${playerName}`;
+  logger(`Score: ${score}`);
 }
 
 function logPlayer(name: string = 'MultiMath player'): void {
@@ -35,3 +45,9 @@ function arm(doc: HTMLDocument) {
 }
 
 arm(document);
+
+const logMessage = (message: string) => console.log(message);
+
+function logError(message: string): void {
+  console.error(message);
+}