mercredi 6 février 2019

Input number output corresponding value

Given these 9 words, display on the page the word corresponding to their chosen number 1.mercury 2.venus 3.earth 4.mars 5.jupiter 6.saturn 7.uranus 8.neptune 9.pluto

Im not sure what I'm missing here Ive done a lot of trial an error and nothing seems to work.

I've tried using numEntry as my comparison for all the if statements and it hasn't worked. When I made var numEntry = true; only Mercury would display. When I made var numEntry = 1,2,3,4,5,6,7,8,9 only pluto would show. I then tried to create a variable for each number and use each once in a comparison like below but every planet shows up instead of the corresponding number to planet.

var numberOfPlanet = prompt("Please enter a number between 1 and 9");

function thePlanets(){  

var numOne = 1;
var numTwo = 2;
var numThree = 3;
var numFour = 4;
var numFive = 5;
var numSix = 6;
var numSeven = 7;
var numEight = 8;
var numNine = 9;


    //do I need to define numberEntry if I use it in my comparisons below? what do I define it as after the = //// I tried defining as true but only mercury will appear, i tried inserting numbers 1 through 9 but only pluto worked//


if(numOne = 1 ){
        document.write("mercury");
    }
if(numTwo = 2 ){
        document.write("venus");
    }
if(numThree = 3 ){
        document.write("earth");
    }
if(numFour = 4 ){
        document.write("mars");
    }
if(numFive = 5 ){
        document.write("jupiter");
    }
if(numSix = 6 ){
        document.write("saturn");
    }
if(numSeven = 7 ){
        document.write("uranus");
    } 
if(numEight = 8 ){
        document.write("neptune");
    }
if(numNine = 9 ){
        document.write("pluto"); 
    }
}
 thePlanets(); 

I just need a number to correspond with the right planet when the user enters that number eg. ( user enters 1 and it displays mercury)

Aucun commentaire:

Enregistrer un commentaire