본문 바로가기

Python_WEB/JavaScript

[Ch9]자바스크립트 객체 연습문제 7

반응형

Q>

인터넷에서 비속어가 사용되면 이것을 검출할 수 있는 함수 check(str)를 작성하여 보자.

check()는 "XXX"를 문자열이 포함하고 있으면 true를 반환한다.

그렇지 않으면 false를 반환한다.

 

A>

<!DOCTYPE html>
<html lang="ko">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Quiz 7</title>
</head>

<body>
    <script>
        function check(str) {
            if (str.match(new RegExp("XXX", "i")) != null) {
                document.write("True");
            } else {
                document.write("False");
            }
        }

        check("buy XXX now");
    </script>
</body>

</html>

 

R>

 

HTML5 + CSS3 + JavaScript로 배우는 웹프로그래밍 기초
국내도서
저자 : 천인국
출판 : 인피니티북스 2013.12.19
상세보기
반응형