편집 기록

편집 기록
  • 프로필 엽토군님의 편집
    날짜2021.02.26

    여러 개의 string을 하나의 변수에 지정하고 싶은데 오류가 생깁니다. - JavaScript


        const arr = ['a', 'b', 'c', 'd', 'e'];
        var x = "b" || "d" || "g" || "h" || "z";
        const the_number_of_x = arr.filter(i => i === x).length;
        if (the_number_of_x === 2) {
            console.log("success!")
        } else {
            console.log("fail!")
        }
    

    x라는 변수에 "b""d"가 있고 arr에도 'b', 'd' 총 2개가 있으니까 the_number_of_x2가 되는 거 아닌가요? 그런데 어째서 "success!"가 아닌 "fail!"이 나오는지 모르겠습니다.

    알려주시면 감사하겠습니다.

  • 프로필 알 수 없는 사용자님의 편집
    날짜2021.02.25

    여러 개의 string을 하나의 변수에 지정하고 싶은데 오류가 생깁니다. - JavaScript


        const arr = ['a', 'b', 'c', 'd', 'e'];
        var x = "b" || "d" || "g" || "h" || "z";
        const the_number_of_x = arr.filter(i => i === x).length;
        if (the_number_of_x === 2) {
            console.log("success!")
        } else {
            console.log("fail!")
        }
    

    x라는 변수에 "b" 와 "d"가 있고 arr에도 b, d 총 2개가 있으니까 the_number_of_x는 2가 되는 거 아닌가요? 그런데 어째서 "success!"가 아닌 "fail!'이 나오는지 모르겠습니다.

    알려주시면 감사하겠습니다.