Created
March 8, 2020 17:27
-
-
Save leigler/e3b198e4e79d5c46bcb891463b74c129 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var square = document.getElementById("square"); | |
var red = 255; | |
var green = 0; | |
var blue = 0; | |
var towardsBlue = true; | |
setInterval(function(){ | |
// template literal: | |
square.style.backgroundColor = `rgb(${red}, ${green}, ${blue})`; | |
if(towardsBlue == true){ | |
blue = blue + 40; | |
red = red - 40; | |
}else{ | |
blue = blue - 40; | |
red = red + 40; | |
} | |
// if we reach the maximums, switch direction | |
if(blue >= 255 && red <= 0){ | |
towardsBlue = false; | |
}else if(red >= 255 && blue <= 0){ | |
towardsBlue = true; | |
} | |
}, 500) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment