본문 바로가기
Frontend/JS100 문제풀이

[JS100] 30번 문제

by 민두이 2023. 4. 1.
728x90
반응형

Q.30

문자 pineapple에는 apple이라는 문자가 숨어 있습니다.
원범이는 이렇듯 문자열 속에 숨어있는 문자를 찾아보려고 합니다.
첫번째 입력에서는 문자열이 입력되고, 두번째에는 찾을 문자가 입력되어야 합니다.그 문자가 시작하는 index를 반환하는 프로그램을 만들어 주세요

입력 pineapple is yummyapple
출력4

Answer

더보기
let sentence = prompt('문장을 입력해주세요');
let vocab = prompt('단어를 입력해주세요');

let result = sentence.indexOf(vocab);
console.log(result);

 

 

참고 개념 

  • IndexOf

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf

 

Array.prototype.indexOf() - JavaScript | MDN

The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.

developer.mozilla.org

 

728x90

'Frontend > JS100 문제풀이' 카테고리의 다른 글

[JS100] 32번 문제  (0) 2023.04.04
[JS100] 31번 문제 (시간 복잡도)  (0) 2023.04.03
[JS100] 21번 문제  (0) 2023.03.31
[JS100] 20번 문제  (0) 2023.03.30
[JS100] 19번 문제  (0) 2023.03.29