한 개의 문자열을 입력받아 해당 문자열에 알파벳 대문자가 몇 개 있는지 알아내는 프로그램을 작성하세요.
첫 줄에 문자열이 입력된다. 문자열의 길이는 100을 넘지 않습니다.
첫 줄에 대문자의 개수를 출력한다.
KoreaTimeGood
3
<html>
<head>
<meta charset="UTF-8" />
<title>출력결과</title>
</head>
<body>
<script>
function solution(str) {
let arr = []
let strSplit = str.split("")
strSplit.forEach((item) => {
if (item === item.toUpperCase()) {
arr.push(item)
}
})
return arr.length
}
let str = "KoreaTimeGood"
console.log(solution(str))
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title>출력결과</title>
</head>
<body>
<script>
function solution(s){
let answer=0;
for(let x of s){
//let num=x.charCodeAt();
//if(num>=65 && num<=90) answer++;
if(x===x.toUpperCase()) answer++;
}
return answer;
}
let str="KoreaTimeGood";
console.log(solution(str));
</script>
</body>
</html>