Switch Statement – JavaScript via /r/learnprogramming


Switch Statement – JavaScript

I'm trying to populate a list using a switch statement, I got it to work using if statements with some help from /u/RudeKettle, but now can't seem to get the same results using a switch statement. I don't think I'm selecting the object correctly out of drop down list. Any thoughts?

Javascript:

 var skillProgram =['Detail Orientated', 'Java', 'Problem Solving']; var skillDataScientist = ['R', 'Analytical Thinker', 'Python', 'Statistics']; var skillDatabase = ['SQL', 'Oracle', 'Organized']; var skillSoftware = ['Detail Orientated', 'C', 'C++', 'Java', 'Organized']; switch(document.getElementsByTagName("option")){ case "programmer": //Joining Array to variable list var list = '<ul><li>' + skillProgram.join('</li><li>') + '</li></ul>' //Creating an unorderd list var newNode = document.createElement('ul'); newNode.innerHTML = list; //Placing contents of newNode into my list element document.getElementById("list").appendChild(newNode); break; 

HTML:

 <select id = "dropdown"> <option disabled selected>What is your dream job to start off?</option> <option value="programmer">Programmer</option> <option value="dataScientist">Data Scientist</option> <option value="databaseAdministrator">Database Administrator</option> <option value="softwareEngineer">Software Engineer</option> </select> <!-- Creating two buttons --> <input type = "button" name = "IF: What skills do I need?" value = "IF: What skills do I need?" onclick="showSkillsIf()"> <input type = "button" name = "SWITCH: What skills do I need?" value = "SWITCH: What skills do I need?" onclick = "showSkillsSwitch()"> <!-- The skills necessary for particular job --> 

Submitted July 14, 2017 at 09:02PM by B2easey
via reddit http://ift.tt/2usXslI

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s