
So when you add 97 ('a') to each of the numbers you get a function mapping of 'a'->'b', 'b'->'c'. All methods and properties can be used without creating a Math object first. This is necessary to accommodate for the fact that 'z' needs to go to 'a', and since we only have 26 characters from 'a' to 'z' that we need to "wrap around" (modulus/ %) The JavaScript Math object allows you to perform mathematical tasks on. It's a clever (but confusing) hack to force all the lowercase letters to the character following it.īecause str has been made to be lowercase by the line str = str.trim().toLowerCase(), str will now only contain values from 97 ('a') to 97+25 = 122 ('z').
#CHAR MATH JAVASCRIPT CODE#
For eg, omCharCode(65) will return you ' A' because the ASCII code for ' A' is standardized by the standard as 65. First of all, let's declare a couple of variables and initialize them with an integer and a float, respectively, then type the variable names back in to check that everything is in order: const myInt 5 const myFloat 6. So to answer your first question: omCharCode(x) is just returning you the character in the standardized ASCII table corresponding to the number x. Enter the commands listed below into your developer tools JavaScript console. So the idea is that each character needs to be stored as a number, and ASCII code is then the standardization for what number corresponds to what character and vice versa.

So how does the computer store characters? That's where ASCII (American Standard Code for Information Interchange) comes in.

Use the JavaScript String split() to divide a string into an array of substrings by a separator. These binary bits can be used to form integers and numbers, but not strings and characters. characters are included in the returned array. Well, as you know, computers don't store characters as 'a', 'b', 'z' or '.', they only accept binary bits (0 or 1).
