Skip to content

Commit 65a2b07

Browse files
committed
secret code app
1 parent 17d5476 commit 65a2b07

File tree

4 files changed

+99
-1
lines changed

4 files changed

+99
-1
lines changed

app.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
console.log("howdy")
2+
3+
let secretCode = '🍕🍕🍱🍳🍢'
4+
let string = ''
5+
let inputElement = document.getElementById("user-input")
6+
let secretImgElement = document.getElementById("secret-img")
7+
console.log('inputElement', inputElement)
8+
// console.warn(secreteCode == string)
9+
10+
function clickPizza() {
11+
string += '🍕'
12+
console.log('☝️🍕')
13+
drawUserInputString()
14+
}
15+
16+
17+
function clickBento() {
18+
string += '🍱'
19+
console.log('☝️🍱')
20+
drawUserInputString()
21+
}
22+
23+
// NOTE foodItem is a parameter. A Block Scoped variable to this function that has no value
24+
// foodItem doesn't have a value until it's called
25+
// onclick="clickFoodButton('🫔')" : foodItem = '🫔'
26+
function clickFoodButton(foodItem) {
27+
string += foodItem
28+
console.log('☝️', foodItem)
29+
drawUserInputString()
30+
}
31+
32+
33+
34+
35+
function checkCode() {
36+
console.warn(secretCode == string)
37+
// the comparison creates a BOOL for the if to check
38+
// True runs the block
39+
// False skips the block
40+
if (secretCode == string) {
41+
console.log("It's TRUE")
42+
secretImgElement.classList.remove('d-none')
43+
// secretImgElement.classList.add('d-none')
44+
} else {
45+
console.log("Else False")
46+
string = ''
47+
drawUserInputString()
48+
}
49+
// ! is NOT, so these are NOT equal
50+
// if (secreteCode !== string) {
51+
// console.log("It's FALSE")
52+
// }
53+
}
54+
55+
56+
57+
function drawUserInputString() {
58+
console.log("current user string", string)
59+
inputElement.innerText = string
60+
}

index.html

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,43 @@
1414
<body data-bs-theme="dark">
1515
<nav>sup <i class="mdi mdi-cow-off"></i></nav>
1616

17+
<main class="container">
18+
<section class="row ">
19+
<div id="user-input" class="bg-black text-warning p-2 rounded">
20+
user input goes here
21+
</div>
22+
<!-- To run a function, use a "event listener" -->
23+
<button onclick="clickPizza()" class="col-md-3 btn btn-secondary">
24+
🍕
25+
</button>
26+
<button onclick="clickBento()" class="col-md-3 btn btn-secondary">
27+
🍱
28+
</button>
29+
<button onclick="clickFoodButton('🍿')" class="col-md-3 btn btn-secondary">
30+
🍿
31+
</button>
32+
<button onclick="clickFoodButton('🫔')" class="col-md-3 btn btn-secondary">
33+
🫔
34+
</button>
35+
<button onclick="clickFoodButton('🍳')" class="col-md-3 btn btn-secondary">
36+
🍳
37+
</button>
38+
<button onclick="clickFoodButton('🍢')" class="col-md-3 btn btn-secondary">
39+
🍢
40+
</button>
41+
42+
<button onclick="checkCode()" class="col-md-6 btn btn-primary">
43+
Enter Code 💷
44+
</button>
45+
46+
<img id="secret-img" class="d-none img-fluid" src="jake.gif" alt="">
47+
</section>
48+
</main>
49+
1750

1851
<!-- NOTE script tags should load at the bottom of the body -->
19-
<script src="example.js"></script>
52+
<!-- <script src="example.js"></script> -->
53+
<script src="app.js"></script>
2054
</body>
2155

2256
</html>

jake.gif

6.15 MB
Loading

style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
nav {
22
min-height: 25px;
33
color: aqua;
4+
}
5+
6+
button:active {
7+
background-color: aqua !important;
48
}

0 commit comments

Comments
 (0)