Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

GT JS2 Week3 #67

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 78 additions & 1 deletion Week-3/Homework/mandatory/1-alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,81 @@
function setAlarm() {}
let isPause = false;
let onPause = false;
let timeLeft = 0;
let countDown;
let onAlarm = false;

function flashBack() {
let alarmColors = ["red", "white"];
let count = 0;
let isAlarm = setInterval(() => {
count++;
document.body.style.backgroundColor = alarmColors[count % 2];
}, 200);
document.getElementById("stop").addEventListener("click", () => {
document.body.style.backgroundColor = "white";
onAlarm = false;
return clearInterval(isAlarm);
});
}

function setAlarm() {
let alarmSet = document.getElementById("alarmSet");
if (!onAlarm) {
if (!isPause) {
timeLeft = Number(alarmSet.value);
if (timeLeft > 0) {
let setButton = document.getElementById("set");
setButton.textContent = "Pause";
isPause = true;
let timeRemaining = document.getElementById("timeRemaining");
countDown = setInterval(function () {
let minLeft = Math.floor(timeLeft / 60);
let secLeft = timeLeft % 60;
timeRemaining.textContent = `Time Remaining: ${("0" + minLeft).slice(
-2
)}:${("0" + secLeft).slice(-2)}`;
if (!timeLeft) {
playAlarm();
flashBack();
isPause = false;
onAlarm = true;
setButton.textContent = "Set Alarm";
return clearInterval(countDown);
}
timeLeft--;
}, 1000);
}
} else {
if (!onPause) {
let setButton = document.getElementById("set");
setButton.textContent = "Continue";
onPause = true;
return clearInterval(countDown);
} else {
let setButton = document.getElementById("set");
setButton.textContent = "Pause";
onPause = false;
let timeRemaining = document.getElementById("timeRemaining");
countDown = setInterval(function () {
let minLeft = Math.floor(timeLeft / 60);
let secLeft = timeLeft % 60;
timeRemaining.textContent = `Time Remaining: ${("0" + minLeft).slice(
-2
)}:${("0" + secLeft).slice(-2)}`;
if (!timeLeft) {
playAlarm();
flashBack();
isPause = false;
onAlarm = true;
setButton.textContent = "Set Alarm";
return clearInterval(countDown);
}
timeLeft--;
}, 1000);
}
}
}
}

// DO NOT EDIT BELOW HERE

Expand Down
8 changes: 6 additions & 2 deletions Week-3/Homework/mandatory/2-quotegenerator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<title>Quote Generator</title>
<script src="quotes.js"></script>

<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
Expand All @@ -12,6 +12,10 @@
<link rel="stylesheet" href="style.css" />
</head>
<body>
<!-- Write your HTML in here -->
<!-- <div id="quoteHolder">
<p>efgsdf</p>
<p>dfdf</p>
</div> -->
<script src="quotes.js"></script>
</body>
</html>
41 changes: 41 additions & 0 deletions Week-3/Homework/mandatory/2-quotegenerator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,44 @@ const quotes = [
author: "Zig Ziglar",
},
];

let colors = ["#70B7D6", "#9C70D6", "#D6CD70", "#D6707C", "#0D2958"];

let div = document.createElement("div");
div.style.backgroundColor = "white";
div.style.margin = "auto";
div.style.marginTop = "250px";
div.style.width = "500px";
div.style.hight = "500px";
div.style.alignContent = "center";
div.style.padding = "50px";

let p = document.createElement("p");
let p1 = document.createElement("p");
p.style.fontWeight = "bold";
p1.style.textAlign = "right";

document.body.appendChild(div);

let btn = document.createElement("button");
btn.innerText = "New quote";
//btn.style.";
div.appendChild(p);
div.appendChild(p1);
div.appendChild(btn);



function getQoute() {
let newQuote = pickFromArray(quotes);
let qouteColor = pickFromArray(colors);
let p = document.querySelectorAll("p");
p[0].innerText = newQuote.quote;
p[1].innerText = newQuote.author;
p[0].style.color = qouteColor;
p[1].style.color = qouteColor;
document.body.style.backgroundColor = qouteColor;
}
getQoute();

btn.addEventListener("click", getQoute);
1 change: 0 additions & 1 deletion Week-3/Homework/mandatory/2-quotegenerator/style.css
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
/** Write your CSS in here **/
3 changes: 2 additions & 1 deletion Week-3/Homework/mandatory/3-slideshow/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<title>Slideshow</title>
<script src="slideshow.js"></script>

<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
Expand All @@ -13,5 +13,6 @@
</head>
<body>
<!-- Write your HTML in here -->
<script src="slideshow.js"></script>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 113 additions & 1 deletion Week-3/Homework/mandatory/3-slideshow/slideshow.js
Original file line number Diff line number Diff line change
@@ -1 +1,113 @@
// Write your code here
// Array of images.
let imgs = [
{ src: "pict/flower.jpg", alt: "flower" },
{ src: "pict/fireStation.jpg", alt: "fire station" },
{ src: "pict/hotel.jpg", alt: "hotel" },
{ src: "pict/highroad.jpg", alt: "highroad" },
];
// Ctreate an element for displaying images
let div = document.createElement("div");
div.style.border = "solid green 15px";
// Create image element
document.body.appendChild(div);
let img = document.createElement("img");

// Set styles
img.style.height = "100%";
img.style.width = "100%";
div.style.width = "70%";

div.appendChild(img);
// Initialize counter and display first image
var count = 0;
img.src = imgs[count].src;
img.alt = imgs[count].alt;

// Create buttons
let btnAutoBack = document.createElement("button");
let btnBack = document.createElement("button");
let btnStop = document.createElement("button");
let btnForward = document.createElement("button");
let btnAutoForward = document.createElement("button");
// Create container for the buttons
let btnHolder = document.createElement("div");
document.body.appendChild(btnHolder);
btnHolder.style.width = "70%";

// Set styles for the buttons
btnAutoBack.style.height = "50px";
btnAutoBack.style.width = "20%";
btnBack.style.height = "50px";
btnBack.style.width = "20%";
btnStop.style.height = "50px";
btnStop.style.width = "20%";
btnForward.style.width = "20%";
btnForward.style.height = "50px";
btnAutoForward.style.height = "50px";
btnAutoForward.style.width = "20%";

// Layout of the buttons
document.body.style.display = "flex";
document.body.style.flexWrap = "wrap";
document.body.style.justifyContent = "center";

// Set names of the buttons
btnAutoBack.innerText = "Auto back";
btnBack.innerText = "Back";
btnStop.innerText = "Stop";
btnForward.innerText = "Forward";
btnAutoForward.innerText = "Auto forward";

// Add the buttons to the container
btnHolder.appendChild(btnAutoBack);
btnHolder.appendChild(btnBack);
btnHolder.appendChild(btnStop);
btnHolder.appendChild(btnForward);
btnHolder.appendChild(btnAutoForward);


// Initialize auto mode
let auto = false;
// Definition of moving images function
function moveImg(forward = true) {
if (forward) {
if (count < imgs.length - 1) {
count++;
} else {
count = 0;
}
} else {
if (!count) {
count = imgs.length;
}
count--;
}
img.src = imgs[count].src;
img.alt = imgs[count].alt;
}

// Add event listener to Back button
btnBack.addEventListener("click", () => !auto ? moveImg(false): NaN);
// Add event listener to Auto Forward button
btnForward.addEventListener("click",() => !auto ? moveImg(): NaN);

let interval;

btnAutoForward.addEventListener("click", () => {
if(!auto)
{auto = true;
interval = setInterval(moveImg, 1000);}
});

btnAutoBack.addEventListener("click", () => {
if(!auto)
{auto = true;
interval = setInterval(() => moveImg(false), 1000);}
});

function stop(){
auto = false;
clearInterval(interval);
}
// Add event listener to Stop button
btnStop.addEventListener("click", stop);
1 change: 0 additions & 1 deletion Week-3/Homework/mandatory/3-slideshow/style.css
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
/** Write your CSS in here **/
Loading