[JavaScript] 글자 랜덤 생성하기 & 색깔 코드 랜덤 생성하기

young·2022년 7월 28일
0

Learn more

목록 보기
20/22
//글자 랜덤 생성: Math.random(), toString(), 36진법
const makeRandomLetter = () => {
  return Math.random().toString(36).slice(2)
}

//색깔 랜덤 생성: Hex, Math.floor(), Math.random(), 16진법
const makeRandomColorCode = () => {
return `#${Math.floor(Math.random()*16777215).toString(16)}`+
}

toString()에 숫자 인자를 넣으면, 해당 숫자 진법을 사용하는 문자열을 반환한다.

profile
즐겁게 공부하고 꾸준히 기록하는 나의 프론트엔드 공부일지

0개의 댓글