Project-2 Colors

jananisankar21419

Janani Sankaralingam

Posted on April 2, 2024

Project-2 Colors

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>

Enter fullscreen mode Exit fullscreen mode

style.css

.container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

Enter fullscreen mode Exit fullscreen mode

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++];  
});
Enter fullscreen mode Exit fullscreen mode

Image description

πŸ’– πŸ’ͺ πŸ™… 🚩
jananisankar21419
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.

Related