As per the slides above, there are two character-related JavaScript functions that you need to know about for these tasks.
"A".charCodeAt(0)
converts the character 'A' into its corresponding integer value, in this case 65. The 0 in the brackets is the character position (starting from 0) of the character in the string "A" that you want the integer value for. For example, "HORSE".charCodeAt(4)
would get the integer value for the character 'E'. If you just want the integer value a single character, just use 0 in the brackets.String.fromCharCode(65)
would give the character corresponding to the integer 65 (which we know from above is capital 'A').
Write a function that takes a character and returns the integer representation of it.
Write a function that takes an integer and returns the character .
Write a function that takes a letter and gives you the letter after it. We recommend you follow the following algorithm:
Write a function that takes two letters and gives the letter halfway between them. For example, the letter halfway between 'a' and 'e' is 'c':
Write code that outputs the characters corresponding to integers in some range of your choice. For example, if your two numbers were 65 and 68, your code should output "65 = A, 66 = B, 67 = C, 68 = D".
You should use a for
loop.
Do the same as above, but your code should first ask the user for each of two characters, i.e. "Enter the character to start from." and "Enter the character to go up to".
You want to 'encrypt' words by replacing each letter with the one above it. So encrypt("Hello")
would output "Ifmmp". Write a function encrypt
which does this. Again, you should consider using a for
loop that builds up your encrypted word character by character.