Created
April 27, 2018 08:17
-
-
Save kandros/8c8c0adf01fd7b6f6661d9dd040ea62c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Traccia: | |
| // Crea una funzione che prende come parametri 2 numeri e li somma e ritorna il risultato | |
| function myFunc(x, y) { | |
| return x + y | |
| } | |
| function test() { | |
| let result = myFunc() | |
| if (typeof result !== 'number') { | |
| throw new Error('myFunc should return a number') | |
| } | |
| const num1 = 10 | |
| const num2 = 15 | |
| result = myFunc(num1, num2) | |
| let expected = num1 + num2 | |
| if (result !== expected) { | |
| throw new Error(`got ${result}, expected: ${expected}`) | |
| } | |
| const num3 = 321 | |
| const num4 = 2 | |
| result = myFunc(num3, num4) | |
| expected = num3 + num4 | |
| if (result !== expected) { | |
| throw new Error(`got ${result}, expected: ${expected}`) | |
| } | |
| const num5 = 31 | |
| const num6 = 2 | |
| result = myFunc(num5, num6) | |
| expected = num5 + num6 | |
| if (result !== expected) { | |
| throw new Error(`got ${result}, expected: ${expected}`) | |
| } | |
| console.log('ok') | |
| } | |
| test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment