Copy link to clipboard
Copied
Essentially, I want to count with letters, like Microsoft Excel does, instead of numbers. So instead of printing "We are at 0", "We are at 1", "We are at 2", etc., I need to print "We are at A", "We are at B", "We are at C", etc...
Copy link to clipboard
Copied
Each character has an ASCII code that you can use to do it. For example, "A" is 65, "B" is 66, etc.
You can convert a character to its code using the charCodeAt method of the String object, and a code to a character using String.fromCharCode(). For example:
"A".charCodeAt(0); //returns 65
String.fromCharCode(65); // returns "A"
So all you have to do is add 65 to your number and then convert it to a character to achieve what you described.
Copy link to clipboard
Copied
Be sure to test for the limit so you don't go past "Z"
Copy link to clipboard
Copied
and how to count++ this?
Copy link to clipboard
Copied
Hi,
Something like this.
var curLetterAsNumber = 65; // start with a
var bContinue = true;
while ( bContinue){
var myDisplayString = "We are at " + String.fromCharCode ( curLetterAsNumber);
console.println ( myDisplayString);
curLetterAsNumber++;
if ( curLetterAsNumber > 90)
{
bContinue = false;
}
}
This code just loops and prints the text to the console, but should give you an idea of how to use it.
Regards
Malcolm
Copy link to clipboard
Copied
Because i use greek Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω
and not English A B C... i try with ascii table 128 who's is A Greek 129 is B Greek but compiler returns me non character a black cycle dot...
Copy link to clipboard
Copied
It would have been helpful if you said that from the beginning...
The code for GREEK CAPITAL LETTER ALPHA is 913.
Copy link to clipboard
Copied
Consider using an array or object to associate a number with the corresponding character. For the English alphabet from A-Z it would be:
var aLetters = ["", "A", "B", "C"]; // continue for the other letters
and you'd then do something like:
// Get the letter corresponding to the number 2
var sLetter = aLetters(2); // Returns "B"
You'd just need to change the single character strings in the array to match what you want to use for each number. With JavaScript, you'd specify the capital Greek A string like this: "\u0391"
So you'd just need to get the unicode values for the other characters and do the same.
Copy link to clipboard
Copied
The codes are sequential. So "\u0391" (or 913) is indeed ALPHA, then "\u0392" (or 914) is BETA, etc.