Change background color between red and green every second

前端 未结 10 1233
终归单人心
终归单人心 2020-12-19 16:10

I\'m trying to make a webpage change the background color every one second using JavaScript. I\'m using setTimeout but I can\'t figure out how to get my variabl

10条回答
  •  一整个雨季
    2020-12-19 16:52

    For one thing, this:

    if (x = 1){
    

    Should be this:

    if(x == 1) {
    

    Your statement sets x to 1, rather than tests it to see if it's 1.

提交回复
热议问题