|
- Create a simple web-page with a Label. Use a for-loop to print out the numbers between 1 and 100 into a string (called something like theOutput) which you then show in the Label.
- Use a printLine variable to "build a line." That is, assemble the various parts of the line by adding them to the printLine variable before outputting the completed line using theOutput += printLine;
- For each number, show the number, then the number of times it's cleanly divisible by 10, so something like:
29) X:2
30) X:3
57) X:5
- Now add how many 5's are in the remainder, after the number is divided by 10, like this:
29) X:2 V:1
30) X:3 V:0
57) X:5 V:1
- Finally, add how many 1's are left after you subtract the 10's and the 5's
29) X:2 V:1 I:4
30) X:3 V:0 I:0
57) X:5 V:1 I:2
- Now, using a nested loop, build the line by printing the number of X's corresponding to the number:
29) XX
30) XXX
57) XXXXX
Your nested loop might look something like:
for (var i=1; i<100; i++) {
//print each number
//figure out how many X's, V's and I's in that number
for (var j=1; j<numberOfXs; j++) {
//print an "X"
}
}
- Now add two more nested loops to print out the V's and I's
- For extra credit, first print a C for the number of 100's in the number. Try this for the numbers between 1 and 1000. So 436 would be: CCCCXXXVI
- Clean the code until you've fixed all the bugs, and then run it and show it to your friends.
|
|