Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Heres a working version, although I'm not sure if the GPA calculation is correct, don't have GPA's in New Zealand so not sure how its calculated. I added some comments to the code it point out where you had gone wrong :)</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;script language="JavaScript"&gt; &lt;!-- var classCtr = 0; // should be initialised to 0 so it can be incremented var nmAnswer; var clsGrade; var totalvalue; var gpatotalvalue = 0; var totalvalue = 0; // set up one dimensional array var myClass = new Array(); //removed some unused variables do { // start columns in second dimension of the array myClass[classCtr] = new Array(); // get values from user and put in array myClass[classCtr][0] = prompt ("Enter Class Name"); myClass[classCtr][1] = prompt ("Enter grade recieved"); myClass[classCtr][2] = {"A":4,"B":3,"C":2,"D":1,"F":0}; //removed the myClass[classCtr][1] part myClass[classCtr][3] = prompt ("Enter credit hours") // accumulate the total value totalvalue = totalvalue + parseFloat(myClass[classCtr][3]); //had class instead of myClass gpatotalvalue = gpatotalvalue + parseFloat(myClass[classCtr][2][ myClass[classCtr][1] ] ); //moved this line above the classCtr++; line so you weren't accessing an undefined variable, there some changes here to access the myClass[classCtr][2] object value correctly.. // add one to the total number classCtr++; nmAnswer = prompt ("Do you have more classes"); } while (nmAnswer == "yes"); // set variable that is used as counter clsGrade = 0; // print out header for content document.write("&lt;H2 align='center'&gt;Grade Point Average&lt;/H2&gt;&lt;br&gt;"); document.write("&lt;table bgcolor='Grey' align='center' border='1' cellpadding='4' width='75%'&gt;"); document.write("&lt;tr&gt;"); document.write("&lt;td&gt;Class Name&lt;/td&gt;&lt;td align='center'&gt;Class Grade&lt;/td&gt;&lt;td align='center'&gt;Grade Credit&lt;/td&gt;"); document.write("&lt;/tr&gt;"); // Loop through array displaying html and javascript values in the array while (myClass[clsGrade]) //the previous conditional would only out put the first "persons" grades so changed this to loop through until all peoples grades { document.write("&lt;tr&gt;"); document.write("&lt;td&gt;"); document.write (myClass[clsGrade][0]); //had class instead of myClass document.write("&lt;/td&gt;"); document.write("&lt;td align='center'&gt;"); document.write (myClass[clsGrade][1]);//had class instead of myClass document.write("&lt;/td&gt;"); document.write("&lt;td align='center'&gt;"); document.write (myClass[clsGrade][3]);//had class instead of myClass document.write("&lt;/td&gt;"); document.write("&lt;/tr&gt;"); document.write("&lt;/td&gt;"); // increment the counter clsGrade++; } // finish the table of data and display the total value document.write("&lt;/Table&gt;"); document.write("&lt;br&gt;"); document.write("&lt;table bgcolor='grey' align='center' border='1' cellpadding='4' width='75%'&gt;"); document.write("&lt;tr&gt;"); document.write("&lt;td&gt;Total value&lt;/td&gt;&lt;td align='center'&gt;" + totalvalue + "&lt;/td&gt;"); document.write("&lt;/tr&gt;"); document.write("&lt;tr&gt;"); document.write("&lt;td&gt;GPA&lt;/td&gt;&lt;td align='center'&gt;" + gpatotalvalue + "&lt;/td&gt;"); document.write("&lt;/tr&gt;"); document.write("&lt;/Table&gt;"); //--&gt; &lt;/script&gt; &lt;/font&gt;&lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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