CAST OF CHARS


Use loops to create unique grids of characters on the page. Let the user choose the size of the grid and the style of the grid, with different character sets, random chars and colors. Make your grids into artwork!

Here is an example of a finished version


Directions
  1. Setup a webpage with a Button and a Label. When the button is clicked, have it run a function called makeGrid() (or another name) which prints out 50 "A"s in the Label.

  2. Change makeGrid() to print the 50 "A"s in a grid, with 10 chars per row. (use theOutput += "<br>")

  3. Add two Input fields above the button, that ask for totalNumCharacters and charsPerRow. Change makeGrid to print totalNumCharacters "A"s instead of 50 . And to break each line after charsPerRow "A"s, instead of 10.

    Test this and make sure it works before moving on.

  4. In your HTML section, add a pulldown to ask the user for a Grid Style. Use a <select> tag and three options:

    <select id= "gridStyle">
             <option value= "asOnly">All As</option>
             <option value="allChars">Show all Characters</option>
             <option value="randomEnglish">Random Ennglish</option>
    </select>
    

  5. In your makeGrid() function, use an if-then switch to print different versions of the grid, based on what the user selected in the pulldown, as in:

    if (gridStyle === "asOnly") {
    
              //do asOnly
    
    } elseif (gridStye === "allChars") {
    
            //do allChars
    
    } elseif (gridStye === "randomEnglish") {  
    

    etc...

  6. Write the AllChars grid style, where you show sequential characters, starting with A.

    Note:
    String.fromCharCode(65); will display "A"
    String.fromCharCode(66); will display "B"

  7. Change AllChars to print the code number and then the character on each line, as in:
      
    65)      A 
    66)      B   
    67)      C 
    etc.
    
    Pick a big number for chars to display, like 5,000, and you'll see different character sets you can play with.

  8. Write a new function to return a random number up to X. something like:
    function randomNumber(max) {
          // return a random number using math.Random() between 0 and max
    }

    Test it by outputting a list of random numbers on the page.

  9. Modify randomNumber to return a number between min and max, as in randomNumber(min, max)

  10. Write the randomEnglish grid Style where you show a random character between A and Z
    Note: the code for "Z" is 91.

  11. Look at the AllChars list to see where character sets begin and end.

    Create other gridStyles such as:
    * Alphabet Repeat - repeat the alphabet, just a-z, as often as needed
    * Random Hebrew - random letters from the hebrew alphabet.
    * Random Greek - random letters from the Greek alphabet.
    * Your own interesting variation.

  12. Add a checkbox that, if checked, assigns a different random color to each letter
Have fun and good luck!


(c) 2017 by Code Craft Academy