dimanche 9 août 2015

Last else if case not working

I'm working on a refactored version of the FizzBuzz test, where a user's entry displays literally UNLESS the entry is any multiple of 3 ("Fizz"), 5 ("Buzz"), or 3 and 5 ("FizzBuzz").

I'm using an if/else if/else if/else condition. Regardless of what rules I associate with it, the last else if case doesn't execute. I'm not sure what's wrong. Can someone advise me?

Here is my current javascript:

function myFunction() {
    var userEntry = prompt("Please enter a number", userEntry);
        if ((userEntry%3==0)&&(userEntry%5==0)) {
            document.getElementById("demo").innerHTML = "FizzBuzz";
        }
        else if (userEntry%5==0) {
            document.getElementById("demo").innerHTML = "Buzz";
        }
        else if (userEntry%3==0) { //this one isn't returning anything at all
            document.GetElementById("demo").innerHTML = "Fizz";
        }
        else {
            document.getElementById("demo").innerHTML = userEntry;
        }
}
<!DOCTYPE html>
<html lang="en">
<head>
        <meta charset="UTF-8">
        <title>Document</title>
        <script src="js/app.js"></script>
<script src="http://ift.tt/wV40hO"></script>
</head>
<body>
<button onclick="myFunction()">What's It Gonna Be??</button>
<p id="demo"></p>
</body>
</html>

Aucun commentaire:

Enregistrer un commentaire