-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e3078d
commit 01e3310
Showing
3 changed files
with
353 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<link rel="stylesheet" href="style.css" /> | ||
<title>Guess My Number!</title> | ||
</head> | ||
|
||
<body> | ||
<!-- Overlay --> | ||
<div class="overlay"></div> | ||
|
||
<div class="prompt "> | ||
<button class="close">×</button> | ||
<h3>Better on PC</h3> | ||
<p>Working to Improve Mobile Version 😁</p> | ||
</div> | ||
|
||
<header> | ||
<h1>Guess My Number!</h1> | ||
<p class="between">(Between 1 and 20)</p> | ||
<button class="btn again">Again!</button> | ||
<div class="number">?</div> | ||
</header> | ||
|
||
<main> | ||
<section class="left"> | ||
<input type="number" class="guess" min="1" max="20" /> | ||
<button class="btn check">Check!</button> | ||
</section> | ||
<section class="right"> | ||
<p class="message">Start guessing...</p> | ||
<p class="label-score">💯 Score: <span class="score">20</span></p> | ||
<p class="label-highscore">🥇 Highscore: <span class="highscore">0</span></p> | ||
</section> | ||
</main> | ||
|
||
<!-- JavaScript --> | ||
<script 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict'; | ||
|
||
let randomNumber = Number(Math.trunc(Math.random() * 20) + 1); | ||
// console.log(randomNumber); | ||
let score = 20; | ||
let highScore = 0; | ||
|
||
const message = document.querySelector('.message'); | ||
const highScoreMessage = document.querySelector('.highscore'); | ||
const scoreMessage = document.querySelector('.score'); | ||
const hiddenNumber = document.querySelector('.number'); | ||
const checkButton = document.querySelector('.check'); | ||
const againButton = document.querySelector('.again'); | ||
|
||
const check = function () { | ||
const userInput = Number(document.querySelector('.guess').value); | ||
if (!userInput) { | ||
message.textContent = 'Enter a number'; | ||
} else if (userInput <= 0 || userInput > 20) { | ||
message.textContent = 'Only between 1 & 20'; | ||
score--; | ||
scoreMessage.textContent = score; | ||
} else if (userInput > randomNumber) { | ||
message.textContent = 'Try Lower'; | ||
score--; | ||
scoreMessage.textContent = score; | ||
} else if (userInput < randomNumber) { | ||
message.textContent = 'Try Higher'; | ||
score--; | ||
scoreMessage.textContent = score; | ||
} else { | ||
message.textContent = 'Winner!!'; | ||
document.querySelector('body').style.backgroundColor = '#60b347'; | ||
hiddenNumber.textContent = randomNumber; | ||
if (score > highScore) { | ||
highScore = score; | ||
highScoreMessage.textContent = highScore; | ||
} | ||
} | ||
}; | ||
|
||
checkButton.addEventListener('click', function () { | ||
check(); | ||
}); | ||
|
||
document.addEventListener('keydown', event => { | ||
if (event.key === 'Enter') check(); | ||
}); | ||
|
||
againButton.addEventListener('click', function () { | ||
score = 20; | ||
scoreMessage.textContent = score; | ||
message.textContent = 'start Guessing...'; | ||
document.querySelector('.guess').value = ''; | ||
document.querySelector('body').style.backgroundColor = '#222222'; | ||
hiddenNumber.textContent = '?'; | ||
randomNumber = Number(Math.trunc(Math.random() * 20) + 1); | ||
}); | ||
|
||
document.querySelector('.close').addEventListener('click', function () { | ||
document.querySelector('.prompt').classList.add('hidden'); | ||
document.querySelector('.overlay').classList.add('hidden'); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
@import url('https://fonts.googleapis.com/css?family=Press+Start+2P&display=swap'); | ||
|
||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: inherit; | ||
} | ||
|
||
html { | ||
font-size: 62.5%; | ||
box-sizing: border-box; | ||
} | ||
|
||
body { | ||
font-family: 'Press Start 2P', sans-serif; | ||
color: #eee; | ||
background-color: #222; | ||
} | ||
|
||
/* Overlay Styling */ | ||
.overlay { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: rgba(0, 0, 0, 0.5); | ||
z-index: 99; | ||
} | ||
|
||
/* Prompt Styling */ | ||
.prompt { | ||
position: fixed; | ||
padding: 23px; | ||
border-radius: 15px; | ||
background-color: #fff; | ||
top: 50%; | ||
left: 50%; | ||
width: 80%; | ||
height: 32%; | ||
transform: translate(-50%, -50%); | ||
z-index: 999; | ||
color: #222; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.prompt .close { | ||
align-self: flex-end; | ||
font-size: 3rem; | ||
font-weight: 600; | ||
padding: 0; | ||
margin-bottom: 5px; | ||
border: none; | ||
background-color: #fff; | ||
color: #444; | ||
cursor: pointer; | ||
} | ||
|
||
.prompt h3 { | ||
margin-top: 5px; | ||
font-size: 2rem; | ||
margin-bottom: 30px; | ||
} | ||
|
||
.prompt p { | ||
font-size: 1.4rem; | ||
line-height: 2; | ||
margin-bottom: 20px; | ||
} | ||
|
||
/* Hidden Class */ | ||
.hidden { | ||
display: none; | ||
} | ||
|
||
/* Mobile Specific Styling */ | ||
@media (min-width: 991px) { | ||
.overlay { | ||
display: none; | ||
} | ||
|
||
.prompt { | ||
display: none; | ||
} | ||
} | ||
|
||
/* Layout Styling */ | ||
header { | ||
position: relative; | ||
height: 35vh; | ||
border-bottom: 7px solid #eee; | ||
} | ||
|
||
main { | ||
height: 65vh; | ||
color: #eee; | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-around; | ||
position: relative; | ||
} | ||
|
||
.left { | ||
width: 52rem; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
.right { | ||
width: 52rem; | ||
font-size: 2rem; | ||
} | ||
|
||
/* Element Styling */ | ||
h1 { | ||
font-size: 4rem; | ||
text-align: center; | ||
position: absolute; | ||
width: 100%; | ||
top: 52%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
} | ||
|
||
.number { | ||
background: #eee; | ||
color: #333; | ||
font-size: 6rem; | ||
width: 15rem; | ||
padding: 3rem 0rem; | ||
text-align: center; | ||
position: absolute; | ||
bottom: 0; | ||
left: 50%; | ||
transform: translate(-50%, 50%); | ||
} | ||
|
||
.between { | ||
font-size: 1.4rem; | ||
position: absolute; | ||
top: 2rem; | ||
right: 2rem; | ||
} | ||
|
||
.again { | ||
position: absolute; | ||
top: 2rem; | ||
left: 2rem; | ||
} | ||
|
||
.guess { | ||
background: none; | ||
border: 4px solid #eee; | ||
font-family: inherit; | ||
color: inherit; | ||
font-size: 5rem; | ||
padding: 2.5rem; | ||
width: 25rem; | ||
text-align: center; | ||
display: block; | ||
margin-bottom: 3rem; | ||
} | ||
|
||
.btn { | ||
border: none; | ||
background-color: #eee; | ||
color: #222; | ||
font-size: 2rem; | ||
font-family: inherit; | ||
padding: 2rem 3rem; | ||
cursor: pointer; | ||
} | ||
|
||
.btn:hover { | ||
background-color: #ccc; | ||
} | ||
|
||
.message { | ||
margin-bottom: 8rem; | ||
height: 3rem; | ||
} | ||
|
||
.label-score { | ||
margin-bottom: 2rem; | ||
} | ||
|
||
@media (max-width: 991px) { | ||
.again { | ||
font-size: 15px; | ||
float: left; | ||
padding: 10px 15px; | ||
} | ||
|
||
.between { | ||
font-size: 1rem; | ||
top: 3rem; | ||
} | ||
|
||
header { | ||
height: 33vh; | ||
padding: 10px; | ||
} | ||
|
||
header h1 { | ||
font-size: 3rem; | ||
top: 52%; | ||
line-height: 1.3; | ||
} | ||
|
||
.number { | ||
font-size: 5rem; | ||
width: 13rem; | ||
} | ||
|
||
main { | ||
overflow: hidden; | ||
flex-direction: column-reverse; | ||
justify-content: space-evenly; | ||
} | ||
|
||
main .right { | ||
display: flex; | ||
flex-direction: column-reverse; | ||
align-items: center; | ||
margin-top: 2rem; | ||
} | ||
|
||
.message { | ||
margin-bottom: 2rem; | ||
} | ||
|
||
.right p:not(.message) { | ||
margin-bottom: 4rem; | ||
} | ||
|
||
.right .label-highscore { | ||
margin-top: 3rem; | ||
margin-bottom: 2.5rem; | ||
} | ||
.left { | ||
margin-top: -15px; | ||
} | ||
} |