-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
function addition(numberOne, numberTwo) { | ||
return numberOne + numberTwo; | ||
} | ||
|
||
function substract(numberOne, numberTwo) { | ||
return numberOne - numberTwo; | ||
} | ||
|
||
function multiplication(numberOne, numberTwo) { | ||
return numberOne * numberTwo; | ||
} | ||
|
||
function division(numberOne, numberTwo) { | ||
if (numberTwo == 0) { | ||
throw new Error("Impossible de diviser par 0 !"); | ||
} | ||
return numberOne / numberTwo; | ||
} | ||
|
||
do { | ||
try { | ||
do { | ||
var choice = prompt("Que souhaitez-vous faire ?\n\n" | ||
+ "1 - Addition\n" | ||
+ "2 - Soustraction\n" | ||
+ "3 - Multiplication\n" | ||
+ "4 - Division\n" | ||
); | ||
choice = Number(choice); | ||
} while (isNaN(choice) || choice < 0 || choice > 4) | ||
|
||
do { | ||
var numberOne = Number(prompt("Premier nombre ?")); | ||
} while (isNaN(numberOne)) | ||
|
||
do { | ||
var numberTwo = Number(prompt("Deuxième nombre ?")); | ||
} while (isNaN(numberTwo)) | ||
|
||
let result; | ||
switch (choice) { | ||
case 1: | ||
result = addition(numberOne, numberTwo); | ||
break; | ||
case 2: | ||
result = substract(numberOne, numberTwo); | ||
break; | ||
case 3: | ||
result = multiplication(numberOne, numberTwo); | ||
break; | ||
case 4: | ||
result = division(numberOne, numberTwo); | ||
break; | ||
default: | ||
throw new Error("L'opération n'existe pas!"); | ||
} | ||
|
||
alert("Résultat : " + result); | ||
} | ||
catch (error) { | ||
alert(error.message); | ||
} | ||
} while (confirm("Voulez-vous continuer ?")) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Calculatrice</title> | ||
</head> | ||
<body> | ||
<script src="code.js"></script> | ||
</body> | ||
</html> |