0

I'm a beginner. The idea of the whole thing is when a user clicks on a button, it prompts the user to insert a color name. Once inserted, the background should become the color the user chose.

Here's what I could come up with:

function changeColor() {
    let newColor = prompt("What color do you want?", "");
    document.getElementsByClassName("container").style.backGroundColor = `${newColor}`;
}

It doesn't work this way, but I have a feeling I'm somewhere close. Would appreciate some advice :)

  • It’s never called `backGroundColor`. It’s `backgroundColor`. `\`${newColor}\`` can be replaced by just `newColor`. You also [forgot to check](//developer.mozilla.org/docs/Web/API/Window/prompt#return_value) if `newColor` is `null`. – Sebastian Simon Oct 20 '21 at 20:05
  • you should attach an onclick event listener to trigger the button – Ekama Emmanuel Uloho Oct 20 '21 at 20:14

0 Answers0