function getColor(flag = true) {
if (flag) {
let sum = '#'
let arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g']
for (let i = 0; i < 6; i++) {
let random = Math.floor(Math.random() * arr.length)
sum += arr[random]
}
return sum
} else {
let r = Math.floor(Math.random() * 266)
let g = Math.floor(Math.random() * 266)
let b = Math.floor(Math.random() * 266)
return `rgb(${r},${g},${b})`
}
}
let str = getColor(true)
document.write(`${str}<br>`)
let str1 = getColor(false)
document.write(`${str1}<br>`)
- | ------ |
console.log(getColor(true))
console.log(getColor(false))