Answer the question
In order to leave comments, you need to log in
How to write a function to output a random number in the range [0, 255]?
Write a function t7 that returns a random color in the format rgb(x,y,z) (string), where x,y,z are random numbers in the range [0, 255].
Answer the question
In order to leave comments, you need to log in
const t7 = () => {
return `rgb(${Math.random()*256<<0}, ${Math.random()*256<<0}, ${Math.random()*256<<0})`;
}
function t7() {
let x = Math.floor(Math.random() * (255 - 0 + 1)) + 0;
let y = Math.floor(Math.random() * (255 - 0 + 1)) + 0;
let z = Math.floor(Math.random() * (255 - 0 + 1)) + 0;
return `rgb(${x}, ${y}, ${z})`;
}
Decision:
function t6(a, b) {
return Math.floor(Math.random() * (a - b + 1)) + b
}
function t7() {
return `rgb(${t6(0, 255)}, ${t6(0, 255)}, ${t6(0, 255)})`
}
document.querySelector('.button').onclick = function () {
document.querySelector('.out').style.background = t7();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question