ROMAN COUNTER


In Roman Notation, letters stood for numbers. And instead of decimal places, the number of symbols indicated the total value.

Write a bot to show simple Roman Notation. For each of the numbers between 1 and 100, print X for the number of 10's, V for the number of 5's and I for and remaining singles. So you would print:

8: XVIII
15: XV
39: XXXVIIII

For an example click here


Directions
  1. 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.

  2. 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;

  3. 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


  4. 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


  5. 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


  6. 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"
              }
              
    }
    

  7. Now add two more nested loops to print out the V's and I's

  8. 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

  9. Clean the code until you've fixed all the bugs, and then run it and show it to your friends.



(c) 2017 by Code Craft Academy