[바닐라JS] 11일차 _ Math module / 랜덤이미지불러오기 / createElement() / appendChild()

하서율·2022년 7월 14일
1

바닐라JS

목록 보기
8/8

6.0 ~ 6.2



6. QUOTES AND BACKGROUND



6.0 Quotes

Math module

Math.ceil() 소수자리가 있으면 무조건 올림

  • Math.ceil(1.1) => 2
  • Math.ceil(1.0) => 1

Math.round() 반올림
Math.floor() 소수자리 버림, 정수 유지
Math.random() 0과 1사이의 랜덤숫자

  • * 숫자 를 해주면 0부터 해당숫자 사이의 랜덤숫자가 나온다.
    ex) Math.random() * 5. => 0과 5사이의 랜덤숫자




6.1 Background

랜덤으로 이미지 불러오기 + JS로 html태그 생성후 추가하기

  1. 이미지 파일명이 들어있는 array를 생성.
  • 파일 이름은 직접입력해야함

    const images = ["0.jpeg","1.jpeg","2.jpeg"];

  1. 랜덤 배열 구하기

    images [Math.floor(Math.random() * images.length )]

  2. createElement()appendChild()로 html에 태그를 추가할 수 있다.

    변수 = document.createElement("태그")
    document.body.appendChild(변수)




6.2 Recap

복습




profile
매일 매일 기록하기

0개의 댓글