Susie enters a hallway at school with 100 lockers numbered 1-100. She goes down the hallway and opens all of the lockers beginning with locker 1 and ending with locker 100. She goes down the hallway again beginning wth locker 1 and ending with locker 100- this time, for every locker that has a number that is a multiple of 2 she closes the locker. She is going down the hallway again beginning wiht locker 1 and ending with locker 100 - this time, for every locker that has a number that is a multiple of 3 she closes the locker if it is open and opens the locker if it is open and opens the locker if it is closed. She repeats this process again for multiples of 4, 5, 6... all the way up to 100.Javascript problem: Any suggestions for coding this?
%26lt;html%26gt;
%26lt;head%26gt;
%26lt;!--
No matter which you select
as ';best answer'; - pick one.
--%26gt;
%26lt;style%26gt;
td.locker {
border: 1px solid black;
color: white;
background-color: black;
font-family: Arial, sans-serif;
font-size: small;
text-align: center;
width: 70px;
}
%26lt;/style%26gt;
%26lt;script%26gt;
function get(eid) {
var d = document;
var r = d.getElementById(eid);
return r;
}
var lockers = new Array();
function initLockers() {
for (var i = 1; i %26lt; 101; i++) {
lockers[i] = 'closed';
}
}
function closeLocker(i) {
get('L' + i).style.color = 'white';
get('L' + i).style.backgroundColor = 'black';
}
function openLocker(i) {
get('L' + i).style.color = 'black';
get('L' + i).style.backgroundColor = 'white';
}
var passNumber = 0;
function doPass() {
passNumber++;
if (100 %26lt; passNumber) {
alert('pass 100 already done - resetting all to initial state - click ';pass'; button again to make first pass');
initLockers();
for (var i = 1; i %26lt; 101; i++) {
closeLocker(i);
}
passNumber = 0;
}
for (var i = 1; i %26lt; 101; i++) {
if (0 == i%passNumber) {
if ('open' == lockers[i]) {
lockers[i] = 'closed';
closeLocker(i);
}
else {
lockers[i] = 'open';
openLocker(i);
}
}
}
reportPass(passNumber);
}
function reportPass(p) {
get('rptPass').innerHTML = 'pass number = ' + p;
}
initLockers();
%26lt;/script%26gt;
%26lt;/head%26gt;
%26lt;body%26gt;
%26lt;table%26gt;
%26lt;tr%26gt;
%26lt;td class=';locker';
id=';L1';%26gt;locker 1%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L2';%26gt;locker 2%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L3';%26gt;locker 3%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L4';%26gt;locker 4%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L5';%26gt;locker 5%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L6';%26gt;locker 6%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L7';%26gt;locker 7%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L8';%26gt;locker 8%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L9';%26gt;locker 9%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L10';%26gt;locker 10%26lt;/td%26gt;
%26lt;/tr%26gt;
%26lt;tr%26gt;
%26lt;td class=';locker';
id=';L11';%26gt;locker 11%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L12';%26gt;locker 12%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L13';%26gt;locker 13%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L14';%26gt;locker 14%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L15';%26gt;locker 15%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L16';%26gt;locker 16%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L17';%26gt;locker 17%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L18';%26gt;locker 18%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L19';%26gt;locker 19%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L20';%26gt;locker 20%26lt;/td%26gt;
%26lt;/tr%26gt;
%26lt;tr%26gt;
%26lt;td class=';locker';
id=';L21';%26gt;locker 21%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L22';%26gt;locker 22%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L23';%26gt;locker 23%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L24';%26gt;locker 24%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L25';%26gt;locker 25%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L26';%26gt;locker 26%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L27';%26gt;locker 27%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L28';%26gt;locker 28%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L29';%26gt;locker 29%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L30';%26gt;locker 30%26lt;/td%26gt;
%26lt;/tr%26gt;
%26lt;tr%26gt;
%26lt;td class=';locker';
id=';L31';%26gt;locker 31%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L32';%26gt;locker 32%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L33';%26gt;locker 33%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L34';%26gt;locker 34%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L35';%26gt;locker 35%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L36';%26gt;locker 36%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L37';%26gt;locker 37%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L38';%26gt;locker 38%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L39';%26gt;locker 39%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L40';%26gt;locker 40%26lt;/td%26gt;
%26lt;/tr%26gt;
%26lt;tr%26gt;
%26lt;td class=';locker';
id=';L41';%26gt;locker 41%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L42';%26gt;locker 42%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L43';%26gt;locker 43%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L44';%26gt;locker 44%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L45';%26gt;locker 45%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L46';%26gt;locker 46%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L47';%26gt;locker 47%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L48';%26gt;locker 48%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L49';%26gt;locker 49%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L50';%26gt;locker 50%26lt;/td%26gt;
%26lt;/tr%26gt;
%26lt;tr%26gt;
%26lt;td class=';locker';
id=';L51';%26gt;locker 51%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L52';%26gt;locker 52%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L53';%26gt;locker 53%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L54';%26gt;locker 54%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L55';%26gt;locker 55%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L56';%26gt;locker 56%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L57';%26gt;locker 57%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L58';%26gt;locker 58%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L59';%26gt;locker 59%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L60';%26gt;locker 60%26lt;/td%26gt;
%26lt;/tr%26gt;
%26lt;tr%26gt;
%26lt;td class=';locker';
id=';L61';%26gt;locker 61%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L62';%26gt;locker 62%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L63';%26gt;locker 63%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L64';%26gt;locker 64%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L65';%26gt;locker 65%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L66';%26gt;locker 66%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L67';%26gt;locker 67%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L68';%26gt;locker 68%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L69';%26gt;locker 69%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L70';%26gt;locker 70%26lt;/td%26gt;
%26lt;/tr%26gt;
%26lt;tr%26gt;
%26lt;td class=';locker';
id=';L71';%26gt;locker 71%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L72';%26gt;locker 72%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L73';%26gt;locker 73%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L74';%26gt;locker 74%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L75';%26gt;locker 75%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L76';%26gt;locker 76%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L77';%26gt;locker 77%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L78';%26gt;locker 78%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L79';%26gt;locker 79%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L80';%26gt;locker 80%26lt;/td%26gt;
%26lt;/tr%26gt;
%26lt;tr%26gt;
%26lt;td class=';locker';
id=';L81';%26gt;locker 81%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L82';%26gt;locker 82%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L83';%26gt;locker 83%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L84';%26gt;locker 84%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L85';%26gt;locker 85%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L86';%26gt;locker 86%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L87';%26gt;locker 87%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L88';%26gt;locker 88%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L89';%26gt;locker 89%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L90';%26gt;locker 90%26lt;/td%26gt;
%26lt;/tr%26gt;
%26lt;tr%26gt;
%26lt;td class=';locker';
id=';L91';%26gt;locker 91%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L92';%26gt;locker 92%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L93';%26gt;locker 93%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L94';%26gt;locker 94%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L95';%26gt;locker 95%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L96';%26gt;locker 96%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L97';%26gt;locker 97%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L98';%26gt;locker 98%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L99';%26gt;locker 99%26lt;/td%26gt;
%26lt;td class=';locker';
id=';L100';%26gt;locker 100%26lt;/td%26gt;
%26lt;/tr%26gt;
%26lt;/table%26gt;
%26lt;form%26gt;
%26lt;input type=';button'; value=';make a locker pass'; onclick=';doPass();'; /%26gt;
%26lt;form%26gt;
%26lt;div id=';rptPass';%26gt;no passes made yet%26lt;/div%26gt;
%26lt;/body%26gt;
%26lt;/html%26gt;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment