Write a program that takes a string as input and finds how many uppercase letters in that string.
A string is entered on the first line. The length of the string does not exceed 100.
KoreaTimeGood
Prints the number of uppercase letters on the first line.
3
for ... of
function solution(s) {
let answer = 0;
for (let x of s) {
if (x === x.toUpperCase()) answer++;
}
return answer;
}
ASCII
codefunction solution(s) {
let answer = 0;
for (let x of s) {
let num = x.charCodeAt();
// uppercase index is 65 ~ 90 in ASCII code
// small index is 97~122 in ASCII code
if (num >= 65 && num <= 90) answer++;
}
return answer;
}