-
Notifications
You must be signed in to change notification settings - Fork 139
Open
Description
Pour calculatrice les deux propositions ci-dessous peuvent-elles être envisagées ?
function calculer(a, string, b) {
if (string == "+") {
return a + b;
} else if (string == "-") {
return a - b;
} else if (string == "*") {
return a * b;
} else if (string == "/") {
return a / b;
}
}
console.log(calculer(4, "+", 6)); // Doit afficher 10
console.log(calculer(4, "-", 6)); // Doit afficher -2
console.log(calculer(2, "*", 0)); // Doit afficher 0
console.log(calculer(12, "/", 0)); // Doit afficher Infinity
//2ème possibilité sous toute réserve
function calculer(a, string, b) {
return eval(a + string + b);
}
console.log(calculer(4, "+", 6)); // Doit afficher 10
console.log(calculer(4, "-", 6)); // Doit afficher -2
console.log(calculer(2, "*", 0)); // Doit afficher 0
console.log(calculer(12, "/", 0)); // Doit afficher Infinity
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels