dimanche 27 mars 2016

If/Else Statement Location--Javascript

I'm working on yet another project for my class, and I'm still trying to get the hang of HTML (really starting to miss Python now, ironically). Anyway, I defined a function that will generate random numbers and I'm trying to build a separate function off of that which will display results based on the randomly generated numbers. I thought a simple if/then statement would work, but since adding the if/then statements, I cannot get the original function to display anything other than the button it initially created at the bottom of the page, even after I comment out the new parts, it still doesn't want to work. I'm lost on whether or not I've misplaced something or made a beginner's error.

This is an example of what I've been working with:

<script>
        function randomNumber() {
        document.getElementById("demo").innerHTML = Math.floor((Math.random() * 5) + 1);
        }
        /*function () {
            if randomNumber= 1 {
            innerHTML = "Option 1"
            }
            if randomNumber= 2 {
            innerHTML = "Option 2"
            }
            if randomNumber= 3 {
            innerHTML = "Option 3"
            }
            if randomNumber= 4 {
            innerHTML = "Option 4"
            }
            if randomNumber= 5 {
            innerHTML = "Option 5"
            }
            }*/
    </script>

Aucun commentaire:

Enregistrer un commentaire