Note that there are some explanatory texts on larger screens.

plurals
  1. POusing an array in javascript
    text
    copied!<p>Hi i'm a beginning programmer, i just started learning javascript. I am trying to build a simple javascript program that will prompt the user to select a name from a list of candidates, and then select which category they want to receive information about. Then program should then display that information. I wrote the code listed below, but from some reason it isn't working and i can't figure out way. Any help would be appreciated. thanks</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;interndatabase&lt;/title&gt; &lt;script type="text/javascript"&gt; //&lt;!CDATA[ //stores data about the applicants applicantName= new array ("Joe","Sarah", "Roger", "Mike"); applicantCategory= new array ("University","Year","SAT","GPA"); applicantInfo= new array ( new array ("Stanford","Senior","2250","3.6"), new array ("UC Berkeley","Junior","2100","3.9"), new array ("MIT","Junior","2200","3.3"), new array ("Carnegie Mellon","Sophomore","2150","3.4") ); //this function should evaluate said data function getInfo (){ var theApplicant=" "; var menuA="Please choose an applicant by typing a number\n"; menuA+="0)Joe\n"; menuA+="1)Sarah\n"; menuA+="2)Roger\n"; menuA+="3)Mike\n"; theApplicant=prompt(menuA); return theApplicant; var theCategory=" "; var menuB="Please Choose a category by typing a number\n"; menuB+="0)University\n"; menuB+="1)Year\n"; menuB+="2)SAT\n"; menuB+="3)GPA\n"; theCategory=prompt(menuB); return theCategory; }//end function //main code evaluates the result, and returns the correct info to the user function main () { var output=" "; var name=getInfo() var category=getInfo() var result=applicantInfo [name] [category]; output="The database belonging to" +applicantName; output+="registers" +result+ "in that category."; alert(output); }//end main &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload