Javascript

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>
This is an example of how to target the background element from HTML with javascript. What would be the way to target a paragraph? Thanks!

```

document.body.style.background = ‘blue’;

<do not remove the three backticks above>

@ithortureu

If I follow your syntax, it should look like this:

document.p.style.selector = value;

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

This is some code i have. It is set up so when I click a button the background changes. I want to make it so it changes the color on It’s own. Current code below( this doesnt show the button that activates it, It works )


function funcToRun() {
    var randomNumber = Math.random();
    if (randomNumber <= 0.10) {
        document.body.style.background = 'red';
    }
    else if (randomNumber <= 0.20) {
        document.body.style.background = 'blue';
    }
    else if (randomNumber <= 0.30) {
        document.body.style.background = 'lime';
    }
    else if (randomNumber <= 0.40) {
        document.body.style.background = 'fuchsia';
    }
    else if (randomNumber <= 0.50) {
        document.body.style.background = 'pink';
    }
    else if (randomNumber <= 0.60) {
        document.body.style.background = 'magenta';
    }
    else if (randomNumber <= 0.70) {
        document.body.style.background = 'orange';
    }
    else if (randomNumber <= 0.80) {
        document.body.style.background = 'aqua';
    }
    else if (randomNumber <= 0.90) {
        document.body.style.background = 'violet';
    }
    else {
        document.body.style.background = 'yellow';
    }
}


This article is about changing background color after a few seconds

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

I have made a code that auto changes color. How do I make it show on screen how many times it has changed. Code below



function funcToRun() {
  window.setTimeout( "funcToRun()", 100);
    var randomNumber = Math.random();
    if (randomNumber <= 0.10) {
        document.body.style.background = 'red';
    }
    else if (randomNumber <= 0.20) {
        document.body.style.background = 'blue';
    }
    else if (randomNumber <= 0.30) {
        document.body.style.background = 'lime';
    }
    else if (randomNumber <= 0.40) {
        document.body.style.background = 'fuchsia';
    }
    else if (randomNumber <= 0.50) {
        document.body.style.background = 'pink';
    }
    else if (randomNumber <= 0.60) {
        document.body.style.background = 'magenta';
    }
    else if (randomNumber <= 0.70) {
        document.body.style.background = 'orange';
    }
    else if (randomNumber <= 0.80) {
        document.body.style.background = 'aqua';
    }
    else if (randomNumber <= 0.90) {
        document.body.style.background = 'violet';
    }
    else {
        document.body.style.background = 'yellow';
    }
}


you could create a paragraph, give it an id and use getElementById so you have a paragraph to which you can push output with innerhtml, then you just need to create a counter, and include it somewhere inside the loop. If you work outside of codecademy, you might also want to include a function call, otherwise, nothing is happening

100ms is very little, you do realize that?