5_hyun
2022. 8. 7. 23:31
반응형
해결법
문자를 for문으로 확인하면서 현재 문자와 현재 문자를 toUpperCase를 사용한 것과 비교해서 같으면 카운트를 올려주면 된다.
코드
<html>
<head>
<meta charset="UTF-8" />
<title>출력결과</title>
</head>
<body>
<script>
function solution(s) {
let answer = 0;
for (let i of s) {
if (i === i.toUpperCase()) {
answer++;
}
}
return answer;
}
let str = "KoreaTimeGood";
console.log(solution(str));
</script>
</body>
</html>
반응형