-
-
Save codecademydev/cf96ba0492f2c1efb8eb78ead2383f5d to your computer and use it in GitHub Desktop.
Codecademy export
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Chore Door!</title> | |
<link href="./style.css" rel="stylesheet" type="text/css"> | |
<link href="https://fonts.googleapis.com/css?family=Work+Sans" rel="stylesheet" type="text/css"> | |
</head> | |
<body> | |
<div class="header"> | |
<img src="https://content.codecademy.com/projects/chore-door/images/logo.svg"/> | |
</div> | |
<div class="title-row"> | |
<img src="https://content.codecademy.com/projects/chore-door/images/star.svg"/> | |
<p class="instructions-title">Instructions</p> | |
<img src="https://content.codecademy.com/projects/chore-door/images/star.svg"/> | |
</div> | |
<table class="instructions-row"> | |
<tr> | |
<td class="instructions-number">1. Hiding behind one of these doors is the ChoreBot.</td> | |
</tr> | |
<tr> | |
<td class="instructions-number">2. Your mission is to open all of the doors without running into the ChoreBot.</td> | |
</tr> | |
<tr> | |
<td class="instructions-number">3. If you manage to avoid the ChoreBot until you open the very last door, you win!</td> | |
</tr> | |
<tr> | |
<td class="instructions-number">4. See if you can score a winning streak!</td> | |
</tr> | |
</table> | |
<div class="door-row"> | |
<img class="door-frame" id="door1" src="https://content.codecademy.com/projects/chore-door/images/closed_door.svg"/> | |
<img class="door-frame" id="door2" src="https://content.codecademy.com/projects/chore-door/images/closed_door.svg"/> | |
<img class="door-frame" id="door3" src="https://content.codecademy.com/projects/chore-door/images/closed_door.svg"/> | |
</div> | |
<div id="start" class="start-row">Good luck!</div> | |
<script type="text/javascript" src="script.js"></script> | |
</body> | |
</html> |
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
// Doors | |
let doorImage1 = document.getElementById("door1"); | |
let doorImage2 = document.getElementById("door2"); | |
let doorImage3 = document.getElementById("door3"); | |
// Doors opened n closed | |
let currentlyPlaying = true; | |
const startButton = document.getElementById("start"); | |
let closedDoorPath = "https://content.codecademy.com/projects/chore-door/images/closed_door.svg"; | |
let botDoorPath = "https://content.codecademy.com/projects/chore-door/images/robot.svg"; | |
let beachDoorPath = "https://content.codecademy.com/projects/chore-door/images/beach.svg"; | |
let spaceDoorPath = "https://content.codecademy.com/projects/chore-door/images/space.svg"; | |
let numClosedDoors = 3; | |
let openDoor1; | |
let openDoor2; | |
let openDoor3; | |
const randomDoorGenerator = () => { | |
choreDoor = Math.floor(Math.random() * numClosedDoors); | |
if (choreDoor === 0){ | |
openDoor1 = botDoorPath; | |
openDoor2 = beachDoorPath; | |
openDoor3 = spaceDoorPath; | |
} else if (choorDoor === 1){ | |
openDoor2 = botDoorPath; | |
openDoor1 = beachDoorPath; | |
openDoor3 = spaceDoorPath; | |
} else { (choreDoor === 2) | |
openDoor3 = botDoorPath; | |
openDoor1 = beachDoorPath; | |
openDoor2 = spaceDoorPath; | |
} | |
} | |
const startRound = () => { | |
door1.src = closedDoorPath; | |
door2.src = closedDoorPath; | |
door3.src = closedDoorPath; | |
numClosedDoors = 3; | |
currentlyPlaying = true; | |
startButton.innerHTML = "Good luck!"; | |
randomChoreDoorGenerator(); | |
} | |
const gameOver(status){ | |
if (status === 'win') { | |
startButton.innerHTML = 'You win! Play again?'; | |
} else { | |
startButton.innerHTML = 'Game over! Play again?'; | |
} | |
currentlyPlaying = false; | |
} | |
startRound(); | |
const isBot = (door) => { | |
if(door.src === botDoorPath) { | |
return true; | |
} else { | |
return false; | |
} | |
function isClicked(door){ | |
if(door.src === closedDoorPath){ | |
return false; | |
} else { | |
return true; | |
} | |
} | |
function playDoor(){ | |
numClosedDoors--; | |
if (numClosedDoors === 0){ | |
gameOver("win"); | |
} else if (isBot(door)) { | |
gameOver("lose"); | |
} | |
// Interaction | |
doorImage1.onclick = () => { | |
if(currentlyPlaying && !isClicked(doorImage1)){ | |
doorImage1.src = openDoor1; | |
playDoor(doorImage1); | |
} | |
} | |
doorImage3.onclick = () => { | |
if(currentlyPlaying && !isClicked(doorImage3) ){ | |
doorImage3.src = openDoor3; | |
playDoor(doorImage3); | |
} | |
} | |
doorImage2.onclick = () => { | |
if(currentlyPlaying && !isClicked(doorImage2)){ | |
doorImage2.src = openDoor2; | |
playDoor(doorImage2); | |
} | |
} | |
startButton.onclick = () => { | |
startRound(); | |
} | |
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
body { | |
background-color: #00ffff; | |
margin: 0px; | |
text-align: center; | |
} | |
.door-frame{ | |
cursor: pointer; | |
padding: 10px; | |
} | |
.header { | |
} | |
.title-row{ | |
margin-top: 42px; | |
margin-bottom: 21px; | |
text-align: center; | |
} | |
.instructions-title{ | |
font-size: 18px; | |
font-family: Work Sans; | |
color: #00ffff | |
display: inline; | |
} | |
.instructions-row { | |
margin: 0 auto; | |
width: 400px; | |
background-color: #ffffff; | |
} | |
.instructions-number{ | |
padding-right: 25px; | |
font-family: Work Sans; | |
font-size: 36px; | |
color: #00ffff | |
} | |
.instructions-text{ | |
padding: 10px; | |
font-family: Work Sans; | |
font-size: 14px; | |
color: #ffffff; | |
} | |
.door-row { | |
text-align: center; | |
} | |
.start-row{ | |
margin: auto; | |
width: 120px; | |
height: 43px; | |
font-family: Work Sans; | |
background-color: #eb6536 | |
padding-top: 18px; | |
font-size: 18px; | |
text-align: center; | |
color: #010165; | |
margin-bottom: 21px; | |
cursor: pointer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment