www.richandlucy.com © www.richandlucy.com
Home | Photos | Stuff | Forum

> Stuff > Lucy's Portfolio! > Javascript Example 6

You have 4 weights with which to weigh 1-40kg stone.

The weights can be on either side of the scales and you do not need to use all the weights every time.

Find the weights required to weigh every weight of stone between 1 and 40

In order to do this you will require:

  • several for loops:
  • 1 for each weight
  • 1 for the amount of stone being weighed
  • another for each weight to indicate whether it is on the left, the right or not on the scales at all.
  • if statement to work out if the weights can be used to weigh that amount of stone
  • break statements to break out of loops that aren't the solution
  • alert statements to check progress at various points in the loops
  • input boxes in an HTML form to display answer

You can see the page created here

This script causes a few alerts and an error warning that your pc will run slowly


2 3 4 5 6 7 8 9 10 11 12 13
© www.richandlucy.com - 2004 All content created and owned by www.richandlucy.com | Contact us