파도파도 나오는 JavaScript

[JS Essentials][Ch2][시작하기] 조건문 Switch

써치킴 2022. 1. 28. 02:34

getRandom.js

export default function random() {
  // Math.floor : 소수점 이하 버림
  return Math.floor(Math.random() * 10);    // 랜덤한 정수 리턴
}

main.js

import random from './getRandom';

const a = random();

// switch 조건문
switch (a) {
  case 0:
    console.log('a is o');
    break;
  case 1:
    console.log('a is 1');
    break;
    default:
    console.log('rest...');
    break;
}