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

Exercice calculatrice #23

Open
nourbenhassen opened this issue Mar 15, 2019 · 3 comments
Open

Exercice calculatrice #23

nourbenhassen opened this issue Mar 15, 2019 · 3 comments

Comments

@nourbenhassen
Copy link

J'ai essayé l'exercice calculatrice avec des conditions IF, mais bizarrement le code ne marche pas.
Voici mon code:

function calculer (number1, operator, number2) {
let result;

if (operator = "+")
result = number1 + number2;

else if (operator = "-")
result = number1 - number2;

else if (operator = "*")
result = number1 * number2;

else if (operator = "/")
result = number1 / number2;

return result;

@tossia
Copy link

tossia commented Mar 17, 2019

Et si utiliser la correction suivante?
operator === "+" ??

@Martialcodeur
Copy link

Plutôt operator ==="+"

Ecrire else (operator ==="/") au lieu de else if (operator ="/") à la 9eme ligne

Écrire après <<return result;>> calculer(2,3);
par exemple number1=2 et number2=3

@greg0r1
Copy link

greg0r1 commented Jun 21, 2019

Il manque le "{" au début et à la fin du if, ainsi qu'à la fin de la fonction. Et rajouter, comme tout le monde a dit, l'opérateur == pour vérifier chaque condition.

    function calculer(nbPremier, operator, nbSecond) {
        let result ;
        if (operator == "+") {
            result = nbPremier + nbSecond;
        }else if(operator == "-"){
            result = nbPremier - nbSecond;
        }
        else if (operator == "*") {
            result = nbPremier * nbSecond;
            }
        else if (operator == "/") {
            result = nbPremier / nbSecond;
        }
        return result;
    }

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

4 participants