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

Tell us what’s happening:

Hello there! I’ve tried logging this a variety of ways and have gotten the output that’s expected each time which is a whole number. Any clue as to what I’m missing here?

const randomIndex = Math.floor(darkColorsArr.length * Math.random());


### Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Build a random background color changer</title>
    <link rel="stylesheet" href="./styles.css" />
    <h1>Random Background Color changer</h1>

      <section class="bg-information-container">
        <p>Hex Code: <span id="bg-hex-code">#110815</span></p>

      <button class="btn" id="btn">Change Background Color</button>
    <script src="./script.js"></script>
/* file: styles.css */
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;

:root {
  --yellow: #f1be32;
  --golden-yellow: #feac32;
  --dark-purple: #110815;
  --light-grey: #efefef;

body {
  background-color: var(--dark-purple);
  color: var(--light-grey);
  text-align: center;

.bg-information-container {
  margin: 15px 0 25px;
  font-size: 1.2rem;

.btn {
  cursor: pointer;
  padding: 10px;
  margin: 10px;
  color: var(--dark-purple);
  background-color: var(--golden-yellow);
  background-image: linear-gradient(#fecc4c, #ffac33);
  border-color: var(--golden-yellow);
  border-width: 3px;

.btn:hover {
  background-image: linear-gradient(#ffcc4c, #f89808);

/* file: script.js */
const darkColorsArr = [

// User Editable Region

function getRandomIndex() {
   console.log(Math.floor(Math.random() * darkColorsArr.length));

// 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/ Safari/537.36

Challenge Information:

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

Hi @improvedoutlook

Try changing the order of the multiplication.

Happy coding

1 Like

Sheesh talk about pedantic! Thought I had tried that but it worked this time. Thanks so much for your help!

1 Like