Project-2 Colors
Janani Sankaralingam
Posted on April 2, 2024
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
<title>Colors</title>
</head>
<body>
<div class="container">
<button id="submit" type="button" class="btn btn-outline-dark">Click Me!</button>
</div>
<script src="script.js"></script>
</body>
</html>
style.css
.container {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
script.js
var colors = ["Orangered","Blue","Yellow","Green","Orange", "Cyan","DodgerBlue", "Violet", "Navy", "Purple", "YellowGreen", "OrangeRed", "SlateBlue", "Salmon", "Crimson", "HotPink", "Magenta"];
var index = 0;
document.querySelector("#submit").addEventListener("click", () => {
if(index > colors.length - 1)
index = 0;
document.body.style.backgroundColor = colors[index++];
});
π πͺ π
π©
Janani Sankaralingam
Posted on April 2, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.