if๋ฌธ ์ค์ฒฉ์ ๋ํด์ ์์๋ณด์.
๋น๋ฐ๋ฒํธ๋ฅผ ์
๋ ฅํ ๋
๋ ๊ฐ์ง ์กฐ๊ฑด์ ํ์๋ก ํ์๋ค.
1. ๊ธธ์ด๊ฐ 6๊ธ์ ์ด์์ผ ๊ฒ.
2. ๊ณต๋ฐฑ์ด ์์ ๊ฒ.
const password = prompt("please enter a new password");
๋ณ์๋ก password๋ฅผ ์ง์ ํ ํ ํ๋กฌํํธ์ฐฝ์ ๋์ ๋ค.

const password = prompt("please enter a new password");
// Password must be 6+ characters
if (password.length >= 6) {
// Password cannot include space
if (password.indexOf(' ') === -1) {
console.log("Valid Password!");
} else {
console.log("Password cannot contain spaces!")
}
} else {
console.log("PASSWORD TOO SHORT! Must be 6+ characters")
}
indexOf(' ')
-1
๊ณต๋ฐฑ์ฒ๋ผ ์กด์ฌํ์ง ์๋ ๊ฒ์ ์ฐพ๋ ๊ฒฝ์ฐ -1 ์ถ๋ ฅ
if (password.indexOf(' ') === -1) {
console.log("Valid Password!");
์ฆ (' ') ๊ดํธ ์์ ๊ณต๋ฐฑ์ด -1 ์ด๋ค => ๊ณต๋ฐฑ์ด ์กด์ฌํ์ง ์๋๋ค.
-1 -> ์กด์ฌํ์ง ์์ ๋ ์ถ๋ ฅ
๋ฐ๋ผ์ ์ ํจํ password๊ฐ ๋ ์ ์์.
"hello".indexOf('h')
0 ์ด ์ถ๋ ฅ๋จ.
์กด์ฌํ๋ ๊ฒ






'javaScript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ARRAY METHODS ์ ์ฌ๋ฌ METHODS (0) | 2022.09.20 |
---|---|
if/else/else-if ๊ตฌ๋ฌธ์ ์ฌ์ฉํด๋ณด์. (0) | 2022.09.19 |