Skip to content

Commit

Permalink
Merge pull request Harshsngh07#229 from mahimasawant/master
Browse files Browse the repository at this point in the history
switch to dark mode in JS
  • Loading branch information
Harshsngh07 authored Oct 8, 2020
2 parents 0f1cf27 + 289087b commit 571926b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
Binary file added Language/Javascript/darkmode/darkmode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions Language/Javascript/darkmode/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>My Webpage</title>
<link rel="stylesheet" href="style.css" />
</head>

<h1>My Webpage</h1>
<div id="welcome"></div>
<h4 id="time"></h4>

<button id="btn" onclick="dark()">switch to dark mode</button>

<script src="webpage.js"></script>
</body>
</html>
14 changes: 14 additions & 0 deletions Language/Javascript/darkmode/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
body {
padding: 25px;
background-color: white;
color: black;
font-size: 25px;
}

.dark-mode {
background-color: black;
color: white;
}
#btn {
border-radius: 12px;
}
22 changes: 22 additions & 0 deletions Language/Javascript/darkmode/webpage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var name = prompt("Please enter your name");

if (name != null) {
document.getElementById("welcome").innerHTML =
"Hello " + name + "! Welcome to my Webpage";

const ctime = document.getElementById("time");

function clock() {
let date = new Date();
let time = date.toLocaleTimeString();
ctime.innerText = time;
}

// clock();

setInterval(clock, 1000);
}
function dark() {
var element = document.body;
element.classList.toggle("dark-mode");
}

0 comments on commit 571926b

Please sign in to comment.