Find-Uppercase

Problem

Write a program that takes a string as input and finds how many uppercase letters in that string.

input

A string is entered on the first line. The length of the string does not exceed 100.

KoreaTimeGood

output

Prints the number of uppercase letters on the first line.

3

Solution

using for ... of

function solution(s) {
	let answer = 0;
	for (let x of s) {
		if (x === x.toUpperCase()) answer++;
	}
	return answer;
}

using ASCII code

function 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;
}