+ 2
Help, lol. What's wrong with this JS.
16 Respuestas
+ 2
nevermind, i got it.
https://code.sololearn.com/Wu3n1NR6WtTp/?ref=app
+ 6
window.onload = function(){
var button = document.getElementById("button");
var rainbow = ["red", "orange","yellow","green","blue","indigo ", "violet"];
function change(){
document.body.style.background = rainbow[Math.floor(7*Math.random())];
}
button.addEventListener("click", change);
}
math>Math
body.background? what is it?
I only know body.style.background
"change()" seriously?
It is "change" bc "click" event will do "change()" when click
Absolutely I can explain more correctly and truly of that. But I'm afraid You will require more confuse
+ 5
It still returns an error in the console why?
+ 4
oh then Your code wrong again should be
document.body.style.background =document.getElementById('thanks').innerHTML = rainbow[Math.floor(7*Math.random())];
document.getElementById('thanks') for select element with include id "thanks"
+ 4
Yay nice
+ 3
Because your script is executed before your html is loaded. So it cant find the button... I suggest you to put your whole script inside window.onload = function () { //your code }
+ 3
....Maybe na?
+ 3
oh sorry
My mistake vision :P
tyvm.innerHTML=document.body.style.background=rainbow[7*Math.random()|0]
no ".color"
+ 3
add
"tyvm.style.color=" in front of the previous answer
+ 3
ah ha I just don't get what you want that's all
+ 2
Unfortunately that isn't working. It's popping a math error. Saying math is undefined.
+ 2
thanks man. i think i got now. thanks for the critique of my code. 👍
+ 2
i am still playing with the code. a
Trying to get the color of the h1 tag to change also and that is what's throwing the error atm
+ 2
so there is no need to use the variable tyvm?
+ 2
Hey man, that fix changes what the h1 says. I want to change the color of the text.
+ 2
check it, it works.