-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #189 from MastersAcademy/4-js_basics_elena-ambitska
4-js_basics elena-ambitska
- Loading branch information
Showing
4 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
homeworks/olena.ambitska_elena-ambitska/4-basics/basics.js
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,30 @@ | ||
const FIELD = document.getElementById('field'); | ||
const FORM_SUBMIT = document.querySelector('.count__button'); | ||
|
||
function updateTemplate(num1, num2) { | ||
const TEMPLATE = ` | ||
<ul class="counter__template"> | ||
<li><b>Additional operation: </b>${num1} + ${num2} = ${Math.round(num1 + num2)};</li> | ||
<li><b>Substract operation: </b>${num1} - ${num2} = ${num1 - num2};</li> | ||
<li><b>Multiplication operation: </b>${num1} * ${num2} = ${Math.round(num1 * num2)};</li> | ||
<li><b>Division operation: </b>${num1} / ${num2} = ${(num1 / num2).toFixed(2)};</li> | ||
<li><b>Modulo: </b>${num1} % ${num2} = ${num1 % num2};</li> | ||
<li><b>Exponentiation operation: </b>${num1} ** ${num2} = ${num1 ** num2};</li> | ||
</ul> | ||
`; | ||
|
||
FIELD.innerHTML = ''; | ||
FIELD.insertAdjacentHTML('beforeend', TEMPLATE); | ||
} | ||
FORM_SUBMIT.addEventListener('click', (e) => { | ||
e.preventDefault(); | ||
const num1 = document.querySelector('.counter__input--first').value; | ||
const num2 = document.querySelector('.counter__input--second').value; | ||
|
||
if (num1 === '' || num2 === '') { | ||
FIELD.innerHTML = '<p class="warning">Fill fields by numbers</p>'; | ||
return; | ||
} | ||
|
||
updateTemplate(+num1, +num2); | ||
}); |
31 changes: 31 additions & 0 deletions
31
homeworks/olena.ambitska_elena-ambitska/4-basics/index.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,31 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<link rel="stylesheet" href="../GamesProject/styles/styles.css"> | ||
<link rel="stylesheet" href="styles.css"> | ||
<title>Basic JS</title> | ||
</head> | ||
<body> | ||
<main class="counter__section"> | ||
<h1 class="section__title">Basic math operation</h1> | ||
<form class="counter"> | ||
<div class="form-group"> | ||
<label for="value-first"></label> | ||
<input type="number" id="value-first" placeholder="Add the first number" class="counter__input--first input__field" value=""> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="value-second"></label> | ||
<input type="number" id="value-second" placeholder="Add the second number" class="counter__input--second input__field" value=""> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<input type="submit" value="Count" class="count__button primary__button"> | ||
</div> | ||
</form> | ||
<div id="field"></div> | ||
</main> | ||
<script src="./basics.js"></script> | ||
</body> | ||
</html> |
25 changes: 25 additions & 0 deletions
25
homeworks/olena.ambitska_elena-ambitska/4-basics/styles.css
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,25 @@ | ||
.counter__section { | ||
margin: 0 auto; | ||
padding: 60px; | ||
} | ||
|
||
.counter__section .section__title { | ||
text-align: center; | ||
} | ||
|
||
.count__button { | ||
margin-top: 22px; | ||
} | ||
|
||
.warning { | ||
margin-top: 24px; | ||
font-size: 26px; | ||
line-height: 1.2; | ||
} | ||
|
||
.counter__template { | ||
margin: 20px auto; | ||
display: flex; | ||
flex-direction: column; | ||
row-gap: 8px; | ||
} |
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