The Web Developer 부트캠프 2022
JS 등호, parseInt, if if else else
거위발바닥
2022. 9. 17. 15:59
== 은 타입을 구분하지 않음, 즉 두 값이 다른 타입이면 두 타입을 같게 해줌.
!= 는 not equal
1 == 1 ture
1 == '1' 둘은 같지 않음 '1'은 string이기에 하지만 두 타입이 같도록 변환되어 변환되어 true로 나옴
1 != 1 false
1 != '2' true
===는 타입을 구분하는 엄격한 등호
!== 는 not equal 하지만 엄격
1 === '1' false
1 !== '1' true
consol.log()를 해야지 콘솔로 로그가 입력됨
consol.log(1+2)
parseInt는 문자열을 받아들여서 정수로 나오게 해줌
let userInput = prompt("please enter a nunber") 10 입력
userInput + 10 = 1010
parseInt(userinput) = 10
parseInt(userinput) + 10 = 20
if, else if else가 있음
let num = Math.floor(Math.random() * 100) + 1
if (num % 2 === 0) {
console.log("even")
console.log(num)
}
else if (num % 2 === 1) {
console.log("odd")
console.log(num)
}
else {
console.log("hmm")
}
1부터 100까지의 숫자중 %(나누기) 2를 해서 나머지가 없으면 even출력, 있으면 odd 출력을하며
전부 아니면 hmm을 출력하는 스크립트이다.
const password = prompt('enter')
if (password.length >= 6) {
if (password.indexOf(' ') === -1) {
console.log("good password")
}
else {
console.log("do not enter space")
}
}
else {
console.log("too short")
}
프롬프트로 password 함수를 받고 함수의 길이가 6 이상이면서 공백이 없으면 ( === -1 ) good password
공백이 있으면 do not enter space
6 글자 미만이면 too short