Skip to content

Commit db088e7

Browse files
authored
initial commit
0 parents  commit db088e7

File tree

3 files changed

+188
-0
lines changed

3 files changed

+188
-0
lines changed

index.html

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Calculadora Básica</title>
7+
<link rel="stylesheet" href="./main.css">
8+
</head>
9+
<body>
10+
<form onsubmit="handlerSubmit(event)" class="container">
11+
<div class="input-values">
12+
<label>Value 1:
13+
<input id="value-1" name="value1" type="number">
14+
</label>
15+
16+
<label for="value-2">Value 2:
17+
<input id="value-2" type="number">
18+
</label>
19+
</div>
20+
<div class="options">
21+
<h3>Options</h3>
22+
<ul>
23+
<li>
24+
<input type="radio" name="chosen-option" id="sum">
25+
<label for="sum">SUM</label>
26+
</li>
27+
<li>
28+
<input type="radio" name="chosen-option" id="subtraction">
29+
<label for="subtraction">SUBTRACTION</label>
30+
</li>
31+
<li>
32+
<input type="radio" name="chosen-option" id="multiplication">
33+
<label for="multiplication">MULTIPLICATION</label>
34+
</li>
35+
<li>
36+
<input type="radio" name="chosen-option" id="division">
37+
<label for="division">DIVISION</label>
38+
</li>
39+
</ul>
40+
</div>
41+
<div>
42+
<h3>Result</h3>
43+
<input id="input-calculate" type="number" readonly>
44+
<input id="button" type="submit" value="Calculate" >
45+
<button id="button-clear">Clear</button>
46+
</div>
47+
</form>
48+
49+
<script src="./main.js"></script>
50+
</body>
51+
</html>

main.css

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
* {
2+
padding: 0;
3+
margin: 0;
4+
box-sizing: border-box;
5+
font-family: monospace;
6+
}
7+
8+
body {
9+
width: 100%;
10+
height: 100vh;
11+
background-color: rgb(252, 252, 252);
12+
display: grid;
13+
place-items: center;
14+
}
15+
16+
17+
.container {
18+
background-color: blue;
19+
border-radius: 16px;
20+
padding: 32px;
21+
color: #fff;
22+
}
23+
24+
.input-values {
25+
display: flex;
26+
gap: 20px;
27+
}
28+
29+
.input-values label {
30+
font-weight: bold;
31+
display: flex;
32+
flex-direction: column;
33+
gap: 10px;
34+
}
35+
36+
div {
37+
margin-bottom: 32px;
38+
}
39+
40+
41+
h3 {
42+
margin-bottom: 8px;
43+
}
44+
45+
ul li {
46+
list-style: none;
47+
margin-bottom: 5px;
48+
}
49+
50+
input[type="radio"],
51+
label {
52+
cursor: pointer;
53+
}
54+
55+
56+
#button,
57+
input,
58+
button {
59+
padding: 3px;
60+
}
61+
62+
#button,
63+
button {
64+
color: #fff;
65+
font-weight: bold;
66+
background-color: #000;
67+
}
68+

main.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
function handlerSubmit(event) {
2+
event.preventDefault()
3+
4+
const chosenOption = document.querySelector('input[name = "chosen-option"]:checked')
5+
console.log(chosenOption)
6+
7+
8+
const inputSum = event.target[2]
9+
const inputSubt = event.target[3]
10+
const inputMultp = event.target[4]
11+
const inputDiv = event.target[5]
12+
const result = event.target[6]
13+
const buttonClear = event.target[8]
14+
15+
16+
const val1 = parseFloat(event.target[0].value)
17+
const val2 = parseFloat(event.target[1].value)
18+
19+
20+
if(chosenOption == inputSum) {
21+
22+
const sum = () => {
23+
return val1 + val2
24+
}
25+
26+
result.value = sum()
27+
28+
29+
}else if (chosenOption == inputSubt){
30+
31+
const subt = () => {
32+
return val1 - val2
33+
}
34+
35+
result.value = subt()
36+
37+
}else if (chosenOption == inputMultp){
38+
39+
const multip = () => {
40+
return val1 * val2
41+
}
42+
43+
result.value = multip()
44+
45+
}else if (chosenOption == inputDiv){
46+
47+
const divd = () => {
48+
return val1 / val2
49+
}
50+
51+
result.value = divd()
52+
53+
}
54+
55+
56+
function clearFields() {
57+
event.target[0].value = ''
58+
event.target[1].value = ''
59+
event.target[6].value = ''
60+
if(chosenOption){
61+
chosenOption.checked = false
62+
}
63+
}
64+
65+
66+
buttonClear.addEventListener('click', clearFields)
67+
68+
69+
}

0 commit comments

Comments
 (0)