alert();경고창
console.log(6/2); 출력
Math.pow(3,2); - 9 Math 객체 이용. 제곱.
Math.round(10.6); -11 반올림
Math.ceil(10.2); - 11 가까운 위의 정수로.(천장)
Math.floor(10.2); - 10 가까운 아래 정수로.(바닥)
Math.sqrt(9) - 3 제곱근.
Math.random(); - 랜덤값
typeof를 쓰면 정보의 타입을 알 수 있다.
typeof 1 - 'number' 숫자
typeof"1"-'string' 문자열로(자바스크립트에서는 문자가 아니라 여러 문자들이 이루어진 문자열로 모든 문자를 파악함.)
alert('달리기는\n 즐겁다'); -- 줄바꿈
alert('달리기는'+'즐겁다'); -- 문자 결합
alert('달리기는'+' '+'즐겁다'); -- 띄어쓰기 추가.
"길이는?".length -- 4-- 길이를 알려줌.
index of-- 위치를 파악
"사전에는".indexOf("사"); --0
"사전에는".indexOf("에"); --2
if(true){alert(1)}
else if(false){alert(2)}
if(id == 'mingi'){
alert('일치')
} else{
alert('불일치')
}
var id= prompt('아이디 입력')
if(id == 'mingi'){
var password = prompt('비밀번호')
if(password == '1111')
{
alert('로그인 성공')
}else{
alert('비밀번호가 다릅니다.')
}
}else{
alert('불일치')
}
논리 연산자 &&(and) 조건문을 간결하게 구성하도록 도와줌.
if(true && false){} --거짓.
var id= prompt('아이디 입력')
var password = prompt('비밀번호')
if(id == 'mingi'&& password == '1111')
{
alert('로그인 성공')
}else{
alert('비밀번호가 다릅니다.')
}