Learn Basic Debugging by Building a Random Background Color Changer - Step 7

Change Background Color

this is what it says

You think the button id is Change Background Color?

Why did you write this in your code?

id="btn"

#2C3E50”,
#34495E”,
#2C2C2C”,
#616A6B”,
#4A235A”,
#2F4F4F”,
#0E4B5A”,
#36454F”,
#2C3E50”,
#800020”,
];

function getRandomIndex() {
const randomIndex = Math.floor(darkColorsArr.length * Math.random());
return randomIndex;
}

const body = document.querySelector(“body”);
const bgHexCodeSpanElement = document.querySelector(“#bg-hex-code”);

function changeBackgroundColor() {
const color = darkColorsArr[getRandomIndex()];

bgHexCodeSpanElement.innerText = color;
body.style.backgroundColor = color;
}
const btn = document.querySelector id =(“click-btn”);
console.log(btn);

What is this code you’ve put, what are you trying to show?

Why did you write this in your code previously?

id="btn"

Is it because that is the correct id?

i am pretty sure it is if it is not then pls tell me what it is

That is correct. Now read this again carefully:

You should fix the id name of “#click-btn” line to match the correct id name in the index.html file.

id=“btn” is it this?

no, it’s not. querySelector accepts a string, you need to change the string. Other changes you made where wrong syntax

Is what what? Not sure I understand what you’re asking exactly. Please read @jwilkins.oboe advice again, I’m not sure how much more clear it could be.

You want to replace the CSS selector in querySelector with the correct button id that you found in the HTML file.

You can also review these for better insight:
https://www.freecodecamp.org/news/queryselector-method-javascript/

https://www.w3schools.com/cssref/css_selectors.php

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.