Skip to content

readyCalc #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
219 changes: 195 additions & 24 deletions bjs/07_Number_and_string/index.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,203 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<head>
<meta charset="UTF-8" />
<title>Калькулятор</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css2?family=Share+Tech+Mono&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<body>
<div class="container">
<div class="row calc-row align-items-center">
<div class="col col-md-4 offset-md-4">
<div class="form-group">
<div class="card" id="calc">
<div class="card-body">
<input class="form-control input-window" id="inputWindow" value="">
<div class="row no-gutters">
<div class="col">
<button class="btn btn-outline-danger form-control" id="btn_clr">C</button>
</div>
</div>
</div>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
crossorigin="anonymous"
/>
<link
href="https://fonts.googleapis.com/css2?family=Share+Tech+Mono&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="container">
<div class="row calc-row align-items-center justify-content-center">
<div class="col col-md-4">
<div class="form-group">
<div class="card" id="calc">
<div class="card-body">
<div class="row no-gutters px-1 py-1">
<input
class="form-control input-window"
id="inputWindow"
value="0"
/>
</div>

<div class="row no-gutters">
<div class="col px-1 py-1">
<button class="btn-danger form-control" id="btn_clr">
C
</button>
</div>

<div class="col-3 px-1 py-1">
<button class="btn btn-secondary form-control" id="btn_sqr">
</button>
</div>

<div class="col-3 px-1 py-1">
<button
class="btn btn-secondary form-control"
id="btn_sum_def"
>
+-
</button>
</div>
</div>

<div class="row row-cols-4 no-gutters">
<div class="col px-1 py-1">
<button
class="btn btn-outline-primary form-control"
id="btn_7"
>
7
</button>
</div>

<div class="col px-1 py-1">
<button
class="btn btn-outline-primary form-control"
id="btn_8"
>
8
</button>
</div>

<div class="col px-1 py-1">
<button
class="btn btn-outline-primary form-control"
id="btn_9"
>
9
</button>
</div>

<div class="col px-1 py-1">
<button class="btn btn-secondary form-control" id="btn_sum">
+
</button>
</div>

<div class="col px-1 py-1">
<button
class="btn btn-outline-primary form-control"
id="btn_4"
>
4
</button>
</div>
<div class="col px-1 py-1">
<button
class="btn btn-outline-primary form-control"
id="btn_5"
>
5
</button>
</div>

<div class="col px-1 py-1">
<button
class="btn btn-outline-primary form-control"
id="btn_6"
>
6
</button>
</div>

<div class="col px-1 py-1">
<button class="btn btn-secondary form-control" id="btn_def">
-
</button>
</div>

<div class="col px-1 py-1">
<button
class="btn btn-outline-primary form-control"
id="btn_1"
>
1
</button>
</div>

<div class="col px-1 py-1">
<button
class="btn btn-outline-primary form-control"
id="btn_2"
>
2
</button>
</div>

<div class="col px-1 py-1">
<button
class="btn btn-outline-primary form-control"
id="btn_3"
>
3
</button>
</div>

<div class="col px-1 py-1">
<button
class="btn btn-secondary form-control"
id="btn_multi"
>
*
</button>
</div>

<div class="col px-1 py-1">
<button
class="btn btn-outline-primary form-control"
id="btn_0"
>
0
</button>
</div>

<div class="col px-1 py-1">
<button
class="btn btn-outline-primary form-control"
id="btn_real"
>
,
</button>
</div>

<div class="col px-1 py-1">
<button class="btn btn-primary form-control" id="btn_calc">
=
</button>
</div>

<div class="col px-1 py-1">
<button
class="btn btn-secondary form-control"
id="btn_divis"
>
/
</button>
</div>
</div>

<div class="row no-gutters px-1 pt-3">
<textarea class="col form-control" id="info"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
<script src="script.js"></script>
</body>
</html>
150 changes: 145 additions & 5 deletions bjs/07_Number_and_string/script.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,152 @@
let lastOperand = 0;
let operation = null;

const inputWindow = document.getElementById('inputWindow');
const info = document.querySelector("#info");
const inputWindow = document.getElementById("inputWindow");

document.getElementById("btn_clr").addEventListener("click", function () {
lastOperand = 0;
operation = null;
inputWindow.value = "0";
});

document.getElementById('btn_clr').addEventListener('click', function () {


document.querySelector("#btn_1").addEventListener("click", function () {
if (inputWindow.value === "0"){inputWindow.value = "";}
inputWindow.value += "1";
});

document.querySelector("#btn_2").addEventListener("click", function () {
if (inputWindow.value === "0"){inputWindow.value = "";}
inputWindow.value += "2";
});

document.querySelector("#btn_3").addEventListener("click", function () {
if (inputWindow.value === "0"){inputWindow.value = "";}
inputWindow.value += "3";
});

document.querySelector("#btn_4").addEventListener("click", function () {
if (inputWindow.value === "0"){inputWindow.value = "";}
inputWindow.value += "4";
});

document.querySelector("#btn_5").addEventListener("click", function () {
if (inputWindow.value === "0"){inputWindow.value = "";}
inputWindow.value += "5";
});

document.querySelector("#btn_6").addEventListener("click", function () {
if (inputWindow.value === "0"){inputWindow.value = "";}
inputWindow.value += "6";
});

document.querySelector("#btn_7").addEventListener("click", function () {
if (inputWindow.value === "0"){inputWindow.value = "";}
inputWindow.value += "7";
});

document.querySelector("#btn_8").addEventListener("click", function () {
if (inputWindow.value === "0"){inputWindow.value = "";}
inputWindow.value += "8";
});

document.querySelector("#btn_9").addEventListener("click", function () {
if (inputWindow.value === "0"){inputWindow.value = "";}
inputWindow.value += "9";
});

document.querySelector("#btn_0").addEventListener("click", function () {
if (inputWindow.value === "0"){
inputWindow.value = "0";
} else {
inputWindow.value += "0";};
});

/*вещественное число*/
document.querySelector("#btn_real").addEventListener("click", function () {
inputWindow.value = inputWindow.value + ".";
});

/*Сумма*/
document.querySelector("#btn_sum").addEventListener("click", function () {
lastOperand = inputWindow.value;
operation = "sum";
inputWindow.value = "";
});

/*Разность*/
document.querySelector("#btn_def").addEventListener("click", function () {
lastOperand = inputWindow.value;
operation = "def";
inputWindow.value = "";
});

/*умножение*/
document.querySelector("#btn_multi").addEventListener("click", function () {
lastOperand = inputWindow.value;
operation = "multi";
inputWindow.value = "";
});

/*Деление*/
document.querySelector("#btn_divis").addEventListener("click", function () {
lastOperand = inputWindow.value;
operation = "divis";
inputWindow.value = "";
});

/*квадратный корень*/
document.querySelector("#btn_sqr").addEventListener("click", function () {
operation = "sqr";
});

/*унарный минус*/
document.querySelector("#btn_sum_def").addEventListener("click", function () {
inputWindow.value = (-inputWindow.value);
});


/*Равно*/
document.querySelector("#btn_calc").addEventListener("click", function () {
if (operation === "sum") {
const result = Number(lastOperand) + Number(inputWindow.value);
info.value += `${lastOperand} + ${inputWindow.value} = ${result} \n`;
operation = "null";
lastOperand = 0;
inputWindow.value = result;
}

if (operation === "sqr") {
const result = Math.sqrt(Number(inputWindow.value));
info.value += `√${inputWindow.value} = ${result} \n`;
operation = "null";
inputWindow.value = result;
}

if (operation === "def") {
const result = Number(lastOperand) - Number(inputWindow.value);
info.value += `${lastOperand} - ${inputWindow.value} = ${result} \n`;
operation = "null";
lastOperand = 0;
inputWindow.value = result;
}

if (operation === "multi") {
const result = Number(lastOperand) * Number(inputWindow.value);
info.value += `${lastOperand} * ${inputWindow.value} = ${result} \n`;
operation = "null";
lastOperand = 0;
inputWindow.value = result;
}

if (operation === "divis") {
const result = Number(lastOperand) / Number(inputWindow.value);
info.value += `${lastOperand} / ${inputWindow.value} = ${result} \n`;
operation = "null";
lastOperand = 0;
operation = null;
inputWindow.value = '';
})
inputWindow.value = result;
}

});
6 changes: 6 additions & 0 deletions bjs/07_Number_and_string/style.css
Original file line number Diff line number Diff line change
@@ -7,3 +7,9 @@
text-align: end;
font-size: x-large;
}

#info {
color:rgb(187, 187, 187);
text-align: right;
height: 200px;
}
Loading