Skip to content

Instantly share code, notes, and snippets.

@guillaumebdx
Created September 22, 2021 12:10
Show Gist options
  • Save guillaumebdx/a8e1634acde20a144deb639ae4af0d49 to your computer and use it in GitHub Desktop.
Save guillaumebdx/a8e1634acde20a144deb639ae4af0d49 to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
let firstValue = prompt('Entrer le chiffre 1');
let operator = prompt('Entrer un opérateur');
let secondValue = prompt('Entrer le chiffre 2');
firstValue = parseInt(firstValue);
secondValue = parseInt(secondValue)
let result = 0;
switch (operator) {
case '+' :
result = firstValue + secondValue;
break;
case '-' :
result = firstValue - secondValue;
break;
case '*' :
result = firstValue * secondValue;
break;
case '/' :
result = firstValue / secondValue;
break;
default :
result = 'Invalid operator';
}
console.log(result);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment