Skip to content

Commit eef2b58

Browse files
committed
updated
1 parent 9ded0a0 commit eef2b58

File tree

5 files changed

+105
-1
lines changed

5 files changed

+105
-1
lines changed

My projects/Mutliplication App/home.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Multiplication App</title>
8+
<link rel="stylesheet" href="style.css">
89
</head>
910
<body>
1011

@@ -17,6 +18,6 @@ <h1 id="question">What is 1 multiply by 1?</h1>
1718
</form>
1819

1920
</section>
20-
21+
<script src="index.js"></script>
2122
</body>
2223
</html>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// to replace the current number we can use random function from the math properties
2+
const num1 = Math.ceil(Math.random()*10)
3+
const num2 = Math.ceil(Math.random()*10)
4+
// converting the id from the html to a variable name
5+
const questionEl = document.getElementById("question");
6+
7+
const inputEl = document.getElementById("input");
8+
9+
const formEl = document.getElementById("form");
10+
11+
const scoreEl = document.getElementById("score");
12+
13+
//in order to prevent the score from remaining 0
14+
let score = JSON.parse (localStorage.getItem("score"));
15+
// to get no erros we just use the "if" statement.. saving in local storage
16+
if(!score){
17+
score = 0;
18+
}
19+
// we are now returning the score from storage and updating the score
20+
scoreEl.innerText = `score: ${score}`;
21+
22+
questionEl.innerText = `What is ${num1} multiply by ${num2}?`
23+
24+
const answerEl = num1 * num2;
25+
26+
// add an eventListener to track when the answer is submited from the form and get the data from the input
27+
// Everytime the answer is submitted we active a if callback function
28+
formEl.addEventListener("submit", ()=>{
29+
//to convert strings into numbers just add the + sign before the element
30+
const userAnswer = +inputEl.value;
31+
if(userAnswer === answerEl){
32+
score++; //add 1 to the score
33+
updateLocalStorage();
34+
35+
}else{
36+
score--; // minus 1 to the score
37+
updateLocalStorage();
38+
}
39+
})
40+
41+
//to store the score insde of the browser we can create a function for that.. ONLY stores strings so we use JSON.stringify
42+
function updateLocalStorage(){
43+
localStorage.setItem("score", JSON.stringify(score));
44+
}
45+
Loading
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
*{
2+
padding: 0;
3+
margin: 0;
4+
box-sizing: border-box;
5+
}
6+
7+
body{
8+
display: flex;
9+
justify-content: center;
10+
align-items: center;
11+
height: 100vh;
12+
font-family: 'Roboto', sans-serif;
13+
text-align: center;
14+
background-image: url(roman-mager-5mZ_M06Fc9g-unsplash.jpg);
15+
background-repeat: no-repeat;
16+
background-size: cover;
17+
}
18+
19+
.form{
20+
background-color: white;
21+
padding: 20px;
22+
box-shadow: -2px -3px 3px 2px black;
23+
border-radius: 25px;
24+
margin: 20px auto;
25+
width: 400px;
26+
}
27+
.score{
28+
margin-bottom: 20px;
29+
text-align: right;
30+
}
31+
.input{
32+
margin-top: 15px;
33+
height: 30px;
34+
width: 100%;
35+
border-color: black;
36+
}
37+
.input::placeholder{
38+
font-size: 17px;
39+
40+
text-align: center;
41+
color: grey;
42+
}
43+
.btn{
44+
margin-top: 15px;
45+
background-color: white;
46+
padding: 3px 5px;
47+
border-radius: 25px;
48+
49+
50+
51+
}
52+
.btn:hover{
53+
cursor: pointer;
54+
box-shadow: 2px 2px 2px black;
55+
background: #482d07;
56+
color: white;
57+
transition: all 0.2s ease-in-out;
58+
}

My projects/Mutliplication App/styles.css

Whitespace-only changes.

0 commit comments

Comments
 (0)