I have been trying to solve this challenge since yesterday and i have reset it as well but i am not sure why it is not working as it should be pls can i get some help
/* file: script.js */
const darkColorsArr = [
"#2C3E50",
"#34495E",
"#2C2C2C",
"#616A6B",
"#4A235A",
"#2F4F4F",
"#0E4B5A",
"#36454F",
"#2C3E50",
"#800020",
];
// User Editable Region
function getRandomIndex() {
return Math.floor(Math.random() * darkColorsArr.length);
}
const randomIndex = getRandomIndex();
console.log("Random index:", randomIndex);
const randomColor = darkColorsArr[randomIndex];
console.log("Random color:", randomColor);
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Challenge Information:
Learn Basic Debugging by Building a Random Background Color Changer - Step 3
Not sure if you tagged the wrong step, or if you are doing way more than the step asks you to. My suggestion is: reset the step once more, and do only what the challenge asks you, on the code you already have.
Update the console statement to print a whole number between 0 and 9 […] with a method […] that rounds a number down to the nearest whole number.
That is one good reason to do the challanges in order, as they complete each other.
You can always search outside material for questions like this as well. Being able to search for answers is always an important part of coding. A lot of everything is already answered in forums, blogs, etc.
stackoverflow tends to not have infos on specific methods or functions, it’s more focused on more complex or abstract problems. Use google, or JavaScript documentation like MDN or devdocs.io to search for a specific method
You are only asked to log out the floored number. You should not access the array using the number inside that function.
If you look at the name of the function, its return value is implied. As such, its call would be used to get the index for array access and the access would not happen inside the function. Otherwise, the function would be named something like getRandomColor and not getRandomIndex.