# Print - The Resistor Color Code Quiz - JavaScriptBank.com

So...you think you know the resistor color code really well? Let's see how well.

HTML
`<BODY onload="colVal(), txtCol(), glimMer();"><SCRIPT language=JavaScript><!--//Written by John Farquharson twisepk@yahoo.com//Completed on Thur May 31 MMI @ 2:09 P.M. EDST//The Resistor Color Code Quiz - This//script may be used provided this notice //remains affixed - DaWorks Web Design  //Works in IE 5.5 and Netscape 6.1 var the_col = [ "#000000", "#AD4A18", "#FF0000", "#FF9C4A", "#FFFF10", "#52B552", "blue", "#730063", "#808080", "#FFFFFF" ]; var the_val = [ "1", "10", "100", "1000", "10000", "100000", "1000000" ]; var randomCol = 0; var index = 0; var s1_val = 0; var s2_val = 0; var s3_val = 0; var the_answer = 0; var new_col = "red"; var mou_col = "blue"; var an_col = "#B552AD";function colVal() {randomCol = Math.floor(the_col.length * Math.random());//randomize the first resistor colorband        index = randomCol;if (index == "0") {randomCol = Math.floor(the_col.length * Math.random());        index = randomCol;}//if first resistor band color is black randomize colors againelse{if (index == "1") {s1_val = 1;}//write index value to variable for math calculationsif (index == "2") {s1_val = 2;}if (index == "3") {s1_val = 3;}if (index == "4") {s1_val = 4;}if (index == "5") {s1_val = 5;}if (index == "6") {s1_val = 6;}if (index == "7") {s1_val = 7;}if (index == "8") {s1_val = 8;}if (index == "9") {s1_val = 9;}window.document.my_form.my_button.style.background = the_col[index];//write color to buttonrandomCol = Math.floor(the_col.length * Math.random());//randomize the second resistor band color        index = randomCol;if (index == "0") {s2_val = 0;}//write index value to variable for math calculationsif (index == "1") {s2_val = 1;} if (index == "2") {s2_val = 2;}if (index == "3") {s2_val = 3;}if (index == "4") {s2_val = 4;}if (index == "5") {s2_val = 5;}if (index == "6") {s2_val = 6;}if (index == "7") {s2_val = 7;}if (index == "8") {s2_val = 8;}if (index == "9") {s2_val = 9;}window.document.my_form.my_button_1.style.background = the_col[index];//write color to buttonrandomCol = Math.floor(the_col.length * Math.random());//randomize the third resistor band color        index = randomCol;if (index >= the_val.length){index = 0;}//if third resistor band color is greater than blue randomize colors window.document.my_form.my_button_2.style.background = the_col[index];//write color to buttons3_val = the_val[index];//read multiplier value into variablethe_answer = ((s1_val * 10) + s2_val) * (s3_val);//do the math -- get the answer} }var cnt_scr= 0;var cnt_guess = 0;var cor_rect = "Correct";var in_cor = "Incorrect";function chkAns(){var usr_ans = window.document.my_form.some_text.value;if (isNaN(parseInt(usr_ans))){//check that only numbers were enteredalert("Please enter only numbers!");}elseif (usr_ans == the_answer){cnt_scr++, cnt_guess++;window.document.my_form.ans_text.value = cor_rect;window.document.my_form.yer_score.value = cnt_scr;window.document.my_form.times_ans.value = cnt_guess;}else{if (usr_ans != the_answer){cnt_guess++;window.document.my_form.ans_text.value = in_cor;window.document.my_form.times_ans.value = cnt_guess;}window.document.my_form.right_ans.value = the_answer + " 0hms";if (the_answer <= "999") {real_answer = the_answer + ' Ohms';}elseif ((the_answer >= "999") && (the_answer <= "1000000")){real_answer = the_answer / 1000 + ' K-Ohms';}elseif(the_answer >= "1000000"){real_answer = the_answer / 1000000 + ' Meg-Ohms';}window.document.my_form.r_answer.value = real_answer;}}function txtCol(){window.document.my_form.my_button.style.color = an_col;window.document.my_form.my_button_1.style.color = an_col;window.document.my_form.my_button_2.style.color = an_col;}var the_timeout;function glimMer(){//make the Next Value button text rotate through the available resistor colors window.document.my_form.the_button.style.color = the_col[index];if (index >= the_col.length){index = 0;}index++;the_timeout = setTimeout('glimMer();', 15);//glimmer color delay speed}document.writeln ('<center><table border="1" width="500" bgcolor="#000000"><tr><td width="180">');document.writeln ('<center><table border="1" width="180" bgcolor="#000000"><tr><td width="80">');document.writeln ('<form name = "my_form" action="">' + '<input type="button" name="my_button" value="&nbsp;1&nbsp;">' + '<input type="button" name="my_button_1" value="&nbsp;2&nbsp;">' + '<input type="button" name="my_button_2" value="&nbsp;3&nbsp;">' + '</td><td width="100">' + '<input type="button" name="the_button" value="Next Value" onMouseOver="window.document.my_form.the_button.style.color = new_col" onMouseOut="window.document.my_form.the_button.style.color = mou_col" onClick="my_form.some_text.value = \'\'; colVal()">');document.writeln ('</tr></td></table>');document.writeln ('<table border="1" width="180" bgcolor="#000000"><tr><td width="180">' + '<center><br>' + '<input type="button" name="guess_button" value="Enter" onClick="chkAns();">&nbsp;' + '<input type="text" name="some_text" size="12"><br><br>'); document.writeln ('<table border="0" width="160"><tr><td><center>');document.writeln ('<input type="button" value="  1  " OnClick="my_form.some_text.value += 1">');document.writeln ('<input type="button" value="  2  " OnCLick="my_form.some_text.value += 2">');document.writeln ('<input type="button" value="  3  " OnClick="my_form.some_text.value += 3">');document.writeln ('</center></tr></td><tr><td><center>');document.writeln ('<input type="button" value="  4  " OnClick="my_form.some_text.value += 4">');document.writeln ('<input type="button" value="  5  " OnCLick="my_form.some_text.value += 5">');document.writeln ('<input type="button" value="  6  " OnClick="my_form.some_text.value += 6">');document.writeln ('</center></tr></td><tr><td><center>');document.writeln ('<input type="button" value="  7  " OnClick="my_form.some_text.value += 7">');document.writeln ('<input type="button" value="  8  " OnCLick="my_form.some_text.value += 8">');document.writeln ('<input type="button" value="  9  " OnClick="my_form.some_text.value += 9">');document.writeln ('</center></tr></td><tr><td><center>');document.writeln ('<input type="button" value="  0  " OnClick="my_form.some_text.value += 0">');document.writeln ('<input type="reset" name="reset" value=" Reset" onClick="my_form.some_text.value = 0">');document.writeln ('<br><font color="#FFFFFF" size="1" face="arial"><u>Enter Your Answer In Ohms</u>!</font>');document.writeln ('<hr size="1" width="160">');document.writeln ('<font color="#FFFFFF" size="1" face="arial">Answer is : ' + '<input type="text" name="ans_text" size="10" ><br>' + 'You Have Had <input type="text" name="times_ans" size="5"> Guesses<br>' + 'You have <input type="text" name="yer_score" size="5"> Correct<br>' + 'Right Answer : <input type="text" name="right_ans" size="12"><br>Or : ' + '<input type="text" name="r_answer" size="12">');document.writeln ('</center>' + '</tr></td></table>');document.writeln ('</form></tr></td></table></td><td width="300">');//----- all html in JavaScript below this line ------document.writeln ('<center><font color="#FFFFFF" size="2" face="Arial"><u>' + 'The Resistor Color Code Quiz' + '</u></font></center>');document.writeln ('<center><table border="0" width="200"><tr><td>');document.writeln ('<br><font color="#FFFFFF" size="1" face="arial">So&#133;you think you know the resistor color code really well? Let\'s see how well!<br><br>Click on the &#147;Next Value&#148; button to display the first resistor value. <br><br>Colored buttons 1, 2 and 3 to the<br>left of the &#147;Next Value&#148; button<br>represent their respective resistor<br>color code bands.<br>');document.writeln ('<br>Use the key pad to input your best guess! <br>The answer is diplayed in Ohms and K-Ohms and the number of correct and incorrect answers are displayed.'); document.writeln ('<br><br>The text box is cleared each time you click on the &#147;Next Value&#148; button');document.writeln ('<br><br>This JavaScript is free-ware provided this notice and header notice remain affixed! Other portions of this script may be freely modified! JavaScript written by:');document.writeln ('<br><br><center><a href="http://www.geocities.com/daworxwebdesign/index.html">DaWorx Web Design</a>');document.writeln ('<br>Creating Your Most Vivid Visions!</font></center>');document.writeln ('</font></tr></td></table></center></center></tr></td></table></center>')//--></SCRIPT></body><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->`