Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intro-javascript/chapitre_5/js/calculatrice.js #8

Open
eliottealderson opened this issue Jun 15, 2017 · 0 comments
Open

intro-javascript/chapitre_5/js/calculatrice.js #8

eliottealderson opened this issue Jun 15, 2017 · 0 comments

Comments

@eliottealderson
Copy link

eliottealderson commented Jun 15, 2017

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant