• 카테고리

    질문 & 답변
  • 세부 분야

    웹 개발

  • 해결 여부

    해결됨

실습4 함수작성방법 예제

23.04.06 16:16 작성 조회수 236

0

const sendVerificationCode = () => {
    const token = String(Math.floor(Math.random() * 1000000)).padStart(6, "0")
    document.getElementById("verification__code").innerText = token
    document.getElementById("verification__code").style.color = "#" + token

}

 

 

const sendVerificationCode = () => {
    document.getElementById("verification__code").innerText = String(Math.floor(Math.random() * 1000000)).padStart(6, "0")
    document.getElementById("verification__code").style.color = "#" + String(Math.floor(Math.random() * 1000000).padStart(6, "0"))

}

상단의 코드와 하단의 코드 중 저는 하단의 코드로 작성했었는데, 이 경우 랜덤한 숫자는 나오는데 색은 변화가 없었습니다. 해당 이유를 알고 싶습니다!

 

답변 1

답변을 작성해보세요.

0

안녕하세요!

아래 string 처리하는 영역을 바꿔주세요.

document.getElementById("verification__code").style.color = "#" + String(Math.floor(Math.random() * 1000000)).padStart(6, "0")

감사합니다.😊

String을 padStart처리해주는 거군요! 이해됐습니다ㅎㅎ 감사합니다!