Exercises 02



Using the ASCII Values of characters

Note that alphabet[4].charCodeAt() gives the ascii value of the 5th element of the string called alphabet

Note that String.fromCharCode(65) gives the letter "A"

  1. Set a string variable and write a function called printEachLetter()to print out each character in the string and its ascii value on a separate line.
    E.g. if the variable was set to “ABC” the console should show:
    A: 65
    B: 66
    C: 67


  2. Set a string variable and write a function called totalOfASCII()to return a total of all of ALL the ascii values of the characters in the string
    E.g. if the variable was set to “ABC” the console should show:
    Total of ascii codes is: 198


  3. Set a string variable and write a function called countLetter() to return a count of how many letter "a"s there are in it.
    E.g. if the variable was set to “Many are the commas in autumn ” the console should show:
    The number of a characters are: 4


  4. Adapt the function from Q3 and generalise it so that it also takes the letter to count as a parameter as well as the string.


Running the Functions

Provide evidence of your code running Exercise 1 here:

Provide evidence of your code running Exercise 2 here:

Provide evidence of your code running Exercise 3 here:

Provide evidence of your code running Exercise 4 here: