Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



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

Posts: 1
Name: Dipa
Trades: 0
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 03:53 PM.. Reason: Forgot to add a few words
sh9di is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-07-2008, 03:48 AM Re: Javascript problem
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
This sounds like homework. You should first attempt the problem and, if stuck, post your code for assistance.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 02-14-2008, 02:46 AM Re: Javascript problem
Average Talker

Posts: 20
Name: Qasim dar
Trades: 0
my GODDDDDDDDDDDD
darfun is offline
Reply With Quote
View Public Profile Visit darfun's homepage!
 
Old 02-14-2008, 09:21 PM Re: Javascript problem
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
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.
logic ali is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Javascript problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.19540 seconds with 12 queries