오보에블로그
[자바스크립트] 기본 세팅 및 문법 본문
728x90
html 기본 틀 작성 (파일 명 : hellow.js , hellow.html)
<!DOCTYPE html>
<html lang=ko>
<head>
<meta charset = "utf-8">
<!-- html 글자 깨짐 방지 -->
<title> 자바스크립트</title>
<script src="hellow.js" defer> </script>
<!-- 자바스크립트 파일 불러오기 -->
<!-- <script>
var hello = "hi every one!";
document.body.innerText = hello;
</script> -->
<!-- html 코드에서 자바스크립트 싫행시키기 ; 필수 -->
</head>
<body>
</body>
</html>
defer : 서버에서 hello.js 파일을 가져오고 바로 코드를 실행한다.
그 코드에서 바디를 렌더링 하지 않았으므로,,, 에러..!
defer를 써놓으면 바디까지 렌더링 한 후에 js 파일 코드 실행
자바스크립트 코드 작성
var jbRandom = Math.random();
var jbRandom = Math.floor(jbRandom * 10 );
var hello = "안녕하세요";
var nothello = "아니..안녕하세요";
if(jbRandom < 5)
{
document.body.innerText = hello;
};
if(jbRandom >= 5)
{
document.body.innerText = nothello;
};
0-9까지의 랜덤 변수를 받고, 만약에 랜덤 변수가 5보다 작으면 hello 변수 출력 , 아니면 nothello 변수 출력
hello.html을 부를때마다 써지는 텍스트가 달라지는것을 알 수 있다.


728x90
'STEADYSTUDY > 넓고 얕게' 카테고리의 다른 글
[자바스크립트] Object 사용법 (0) | 2020.07.11 |
---|---|
[자바스크립트] 자바스크립트 파일에서 console.log 사용 (0) | 2020.07.11 |
[WebAssembly] 기본 syntax 의미( semantic) (0) | 2020.07.08 |
webassembly semantic rules (0) | 2020.07.08 |
[웹어셈블리] wat 파일 sexp list 변환 (0) | 2020.07.03 |