-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev.html
189 lines (176 loc) · 6.25 KB
/
dev.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mind Math</title>
<style>
body {
font-family: Arial, sans-serif;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
flex-direction: column;
margin: 50;
}
.content {
text-align: center;
}
.action-button {
position: absolute;
bottom: 200px;
left: 50%;
transform: translateX(-50%);
background-color: #3790a0;
border: none;
color: black;
padding: 17px 15px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border-radius: 50%; /* Add border-radius for round shape */
cursor: pointer;
}
h1, h2 {
position: absolute;
left: 50%;
transform: translateX(-50%);
}
h1 {
top: 40px;
}
h2 {
top: 100px;
}
nav {
background-color: #333;
position: fixed;
left: 0;
bottom: 0;
width: 100%;
z-index: 1000;
}
nav ul {
list-style-type: none;
margin: 0;
padding: 0;
text-align: center;
}
nav ul li {
display: inline;
}
nav ul li a {
display: inline-block;
padding: 14px 20px;
text-decoration: none;
color: white;
transition: background-color 0.3s;
}
nav ul li a:hover {
background-color: #575757;
}
/* Active link styling */
nav ul li a.active {
background-color: #006070;
}
.app-name {
color: white;
font-size: 18px;
font-weight: bold;
}
</style>
</head>
<body>
<div class="content" id="content">
<h1 id="displayNumbers">0 + 0</h1>
<h2 id="answer">ans: 0</h2>
<div>
<button id="actionButton" class="action-button">Go!</button>
</div>
</div>
<div>
<nav>
<div class="app-name" style="padding: 15px; position: absolute;">Mind Math</div>
<ul>
<li><a href="#" id="additionLink" class="active">Addition</a></li>
<li><a href="#" id="subtractionLink">Subtraction</a></li>
<li><a href="#" id="multiplicationLink">Multiplication</a></li>
<li><a href="#" id="divisionLink">Division</a></li>
</ul>
</nav>
</div>
<script>
let num = 0;
let numb = 0;
let show = true;
let functionality = true; // True - Generate, False - Toggle Result
let currentPage = 'addition'; // Track which operation page is active
const randomNumInRange = (min, max) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
const handleClick = () => {
if (functionality) {
// Generate Functionality
num = randomNumInRange(1, 50);
numb = randomNumInRange(50, 100);
show = false;
} else {
// Toggle Sum, Difference, Product, or Quotient
show = !show;
}
// Update the display
updateDisplay();
// Switch functionality for next click
functionality = !functionality;
};
const updateDisplay = () => {
if (currentPage === 'addition') {
document.getElementById('displayNumbers').innerText = `${num} + ${numb}`;
document.getElementById('answer').innerText = show ? `ans: ${num + numb}` : '';
} else if (currentPage === 'subtraction') {
document.getElementById('displayNumbers').innerText = `${num} - ${numb}`;
document.getElementById('answer').innerText = show ? `ans: ${num - numb}` : '';
} else if (currentPage === 'multiplication') {
document.getElementById('displayNumbers').innerText = `${num} * ${numb}`;
document.getElementById('answer').innerText = show ? `ans: ${num * numb}` : '';
} else if (currentPage === 'division') {
document.getElementById('displayNumbers').innerText = `${num} ÷ ${numb}`;
document.getElementById('answer').innerText = show ? `ans: ${(num / numb).toFixed(2)}` : ''; // Round to 2 decimal places
}
};
// Event listeners for operation navigation
document.getElementById('additionLink').addEventListener('click', () => {
currentPage = 'addition';
setActivePage('addition');
updateDisplay();
});
document.getElementById('subtractionLink').addEventListener('click', () => {
currentPage = 'subtraction';
setActivePage('subtraction');
updateDisplay();
});
document.getElementById('multiplicationLink').addEventListener('click', () => {
currentPage = 'multiplication';
setActivePage('multiplication');
updateDisplay();
});
document.getElementById('divisionLink').addEventListener('click', () => {
currentPage = 'division';
setActivePage('division');
updateDisplay();
});
const setActivePage = (page) => {
document.querySelectorAll('nav ul li a').forEach(link => {
link.classList.remove('active');
});
document.getElementById(`${page}Link`).classList.add('active');
};
// Button click listener
document.getElementById('actionButton').addEventListener('click', handleClick);
// Initial display
updateDisplay();
</script>
</body>
</html>