Reply
Javascript problem
Old 02-06-2008, 02:52 PM Javascript problem
Junior Talker

Posts: 1
Name: Dipa
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.

Can someone help me code out this problem?

HELP!!!!!!!!

Last edited by sh9di : 02-06-2008 at 02:53 PM. Reason: Forgot to add a few words
sh9di is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 02-07-2008, 02:48 AM Re: Javascript problem
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 984
Name: Jeremy Miller
Location: Reno, NV
This sounds like homework. You should first attempt the problem and, if stuck, post your code for assistance.
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 02-14-2008, 01:46 AM Re: Javascript problem
Novice Talker

Posts: 11
Name: Qasim dar
my GODDDDDDDDDDDD
__________________
http://darfun.net.tc Softwares Web
http://darfuns.com Fun and Entertainment Portal
darfun is offline
Reply With Quote
View Public Profile Visit darfun's homepage!
 
Old 02-14-2008, 08:21 PM Re: Javascript problem
logic ali's Avatar
Skilled Talker

Posts: 85
The key is the remainder operator - %
This is how I would do it, but you may raise eyebrows if you submit it.
Code:
<script type='text/javascript'>

for(var i=0, lockers=[]; i<100; i++)
 lockers[i]=true; //true=open
 
for(var i=2, j; i<101; i++)
 for(j=1; j<101; j++)
  if( !(j%i) )
   lockers[j-1]^=true;  
 
</script>
If you had to represent this graphically, you could add:
Code:
for(var i=0; i<100; i++)
 document.write("["+(i+1)+"]"+(lockers[i]?"Open":"Closed")+((i&&!((i+1)%10))?"<br>":" "));
No PMs please.
__________________
556E677261746566756C204261737461726473
logic ali is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Javascript problem
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11669 seconds with 12 queries