Skip to content

Commit 5fcfb03

Browse files
committed
fix: 난수가 6자리 미만일 때, 6자리 숫자로 보강해주는 코드 추가
1 parent c0ca2ae commit 5fcfb03

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

project1-colors/src/Button.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ export default function Button({ $target, onClick }) {
55

66
$button.addEventListener("click", (e) => {
77
const generateRandomColorCode = () => {
8-
return Math.floor(Math.random() * 16777215).toString(16);
8+
const randomHex = Math.floor(Math.random() * 16777215).toString(16);
9+
return randomHex.length < 6
10+
? `${"0".repeat(6 - randomHex.length)}${randomHex}`
11+
: randomHex;
912
};
1013
onClick(generateRandomColorCode());
1114
});

0 commit comments

Comments
 (0)