//주어진 단어(word)에 특정 알파벳(ch)이 몇 번 들어가는지 세어주는 함수
function countCharacter(word, ch) {
var count = 0;
word=word.toUpperCase();
ch=ch.toUpperCase();
for(var i=0; i<word.length;i++){
if(word[i]==ch){
count++;
}
}
// 코드를 작성해주세요.
return count;
}
// 단어 word에 알파벳 'A'가 몇 번 나오는지 세어주는 함수
function countA(word) {
// 코드를 작성해주세요.
return countCharacter(word, 'A');
}
// 테스트 코드
console.log(countCharacter('AbaCedEA', 'E'));
console.log(countCharacter('AbaCedEA', 'X'));
console.log(countA('AbaCedEA'));
'컴퓨터 프로그래밍 > JQuery' 카테고리의 다른 글
confirm() (0) | 2020.05.28 |
---|---|
each() (0) | 2020.05.28 |
Form fields: select (0) | 2020.05.28 |
html(), text(), val() (0) | 2020.05.28 |
로그인창 활성화 (0) | 2020.05.27 |