JavaScript Project | Build Simple Calculator With JavaScript HTML CSS

JavaScript Project | Build Simple Calculator With JavaScript HTML CSS

Tech2 etc

2 года назад

204,916 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Olowonla Faruq
Olowonla Faruq - 27.09.2023 19:06

thanks i understand the video but the api has being taken down,not working

Ответить
Better Health Now
Better Health Now - 25.09.2023 18:23

why do the buttons need a 2nd class? like btn btn-grey ?

Ответить
Shivam Kumar
Shivam Kumar - 27.08.2023 19:29

why my equal button showing ' undefined ' 😑😑😫😫

Ответить
Aditya Gaikwad
Aditya Gaikwad - 22.08.2023 16:41

Here is the solution for your que:

if you have a equal undefined error remove 'btn' class in equal in html...

Ответить
LakshyaSingh
LakshyaSingh - 15.08.2023 10:22

Hello guys, my equal button not working, when i press it, it shows undefined can any one help me out with this

html code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<section class="calculator">
<form >
<input type="text" class="screen">
</form>
<div class="buttons">
<button type="button" class="btn btn-yellow" data-num="*">*</button>
<button type="button" class="btn btn-yellow" data-num="/">/</button>
<button type="button" class="btn btn-yellow" data-num="-">-</button>
<button type="button" class="btn btn-yellow" data-num="+">+</button>

<button type="button" class="btn btn-grey" data-num="9">9</button>
<button type="button" class="btn btn-grey" data-num="8">8</button>
<button type="button" class="btn btn-grey" data-num="7">7</button>
<button type="button" class="btn btn-grey" data-num="6">6</button>
<button type="button" class="btn btn-grey" data-num="5">5</button>
<button type="button" class="btn btn-grey" data-num="4">4</button>
<button type="button" class="btn btn-grey" data-num="3">3</button>
<button type="button" class="btn btn-grey" data-num="2">2</button>
<button type="button" class="btn btn-grey" data-num="1">1</button>
<button type="button" class="btn btn-grey" data-num="0">0</button>
<button type="button" class="btn btn-grey" data-num=".">.</button>

<button type="button" class="btn btn-equal">=</button>
<button type="button" class="btn btn-c">C</button>
</div>
</section>
<script src="script.js"></script>
</body>
</html>

--------------------------------------------------------------

javascript code:-

(function() {
let screen = document.querySelector('.screen');
let buttons = document.querySelectorAll('.btn');
let clear = document.querySelector('.btn-c');
let equal = document.querySelector('.btn-equal');

buttons.forEach(function(button){
button.addEventListener('click', function(e){
let value = e.target.dataset.num;
screen.value += value;
})
});

equal.addEventListener('click', function(e){
if (screen.value === '') {
screen.value = "";

} else {
let ans = eval(screen.value);
screen.value = ans;
}
})


clear.addEventListener('click', function(e){
screen.value = "";
})
})();

Ответить
Gaming FF Noob
Gaming FF Noob - 14.08.2023 19:34

bro 4*4undefine plz fix this problem

Ответить
Ajay Devgan
Ajay Devgan - 07.08.2023 14:21

Everything is perfect sir you are awesome you gained my respect and a subscriber

Ответить
stephen Gichia
stephen Gichia - 31.07.2023 09:44

if it's not working check if you remerbered to invoke the function

Ответить
Victoria Azola
Victoria Azola - 30.06.2023 05:02

I did my equal button like this and it worked (also deleted de btn class in the html):

equal.addEventListener("click", (e) => {
if (screen.value !== " ") { //if the screen isn´t empty
let answer = eval(screen.value) //we calculate the aswer
screen.value = " "; //clear the screen
screen.value += answer; //and show the answer
}
})

Ответить
Tanzeela Ghafoor
Tanzeela Ghafoor - 25.06.2023 10:55

Mery calculator project MN click ki funtionaly q ni add ho rhi???

Ответить
Awate Keerthi
Awate Keerthi - 23.06.2023 18:33

Thank you🎉

Ответить
Old Nollywood movies channel
Old Nollywood movies channel - 22.06.2023 14:30

Can anyone please write down the first code in that css file that was written down
I can't see it clearly

Ответить
prince kaushikk
prince kaushikk - 26.05.2023 07:39

first of all thank you explaining in easy or simple way. you simplify all line of code very easy everyone can understand your code. i have a suggestion for you brother make a second channel where you upload same tutorial but in hindi beacuse in hindi code no one can explain like you.

Ответить
Mohit Kumar
Mohit Kumar - 23.05.2023 19:48

Amazing knowledge about front end

Ответить
Amen Etefia
Amen Etefia - 15.05.2023 13:08

bro what are you typing when did you type ( please enter ) i never saw it, and the code it not even working perfectly my = is doing the job of my clear bro

Ответить
Sean Smith
Sean Smith - 02.05.2023 06:50

If you want to round the answer to a particular number of decimal places, you can set the screen value as follows:

screen.value = answer.toFixed(3)

The 3 is the number of decimal places you would like the result to show. This will avoid any really long answers from going off the side of the screen

Ответить
Arit Nath
Arit Nath - 24.04.2023 18:39

what is that e.target.dataset.num?????????????
please somebody explain. where is the num, dataset coming from

Ответить
Abhay Narayan
Abhay Narayan - 21.04.2023 05:58

where it is wrong
please anyone??
(function(){

let screen = document.querySelector('.screen');
let buttons = document.querySelectorAll('.btn');
let clear = document.querySelector('.btn-cancel');
let equal = document.querySelector('.btn-result');

buttons.forEach(function(button){
button.addEventListener("click",function(e){
let value=e.target.dataset.num;
screen.value+=value;
})
});


})();

Ответить
xenone banihal
xenone banihal - 16.04.2023 10:26

equal button is showing undefined in screen.value
pl guide

Ответить
Deba Dey
Deba Dey - 14.04.2023 11:13

Please don't go on adding event listeners to every button as it will make the code inefficient brother.
Rather use event delegation pattern and apply the event listener on button container class.
Anyway, great tutorial!!

Ответить
Ryan Boland
Ryan Boland - 13.04.2023 22:49

8.03

Ответить
Ciarán
Ciarán - 11.04.2023 20:15

Typed the style.css .calculator part exactly the same as yours but there is no rectangle box appearing in browser

Ответить
Sahira Ahamed🥰
Sahira Ahamed🥰 - 10.04.2023 17:29

Alhamdulillah.. Understood👏

Ответить
Chandra prakash
Chandra prakash - 30.03.2023 19:42

❤Thanku so much Bhai ❤

Ответить
Matheus Souza
Matheus Souza - 30.03.2023 17:58

Thank you for this playlist

Ответить
Liam Aiken
Liam Aiken - 29.03.2023 16:31

Do NOT use eval()
Executing JavaScript from a string is an BIG security risk.

With eval(), malicious code can run inside your application without permission.

With eval(), third-party code can see the scope of your application, which can lead to possible attacks.

Ответить
Nkdsnk
Nkdsnk - 22.03.2023 23:21

So simple and clear instructions. Very good job and thank you! Subscribed!

Ответить
Animal Lover
Animal Lover - 21.03.2023 12:29

how to set input limit ?

Ответить
Anime Zone
Anime Zone - 18.03.2023 23:16

If Somebody wants to delete one digit then how he/se can do so, there must be a delete button. If Someone have any Idea then Kindly help me.

Ответить
Rituraj Pathak
Rituraj Pathak - 17.03.2023 18:07

Whats the purpose of wrapping everything around the function? Can someone tell me?

Ответить
Clarisse Aguirre
Clarisse Aguirre - 14.03.2023 17:10

this was very useful to me I almost cried because I thought I won't make the deadline

🤧

Ответить
Mohamed Ahmed
Mohamed Ahmed - 08.03.2023 19:10

I have a problem when i click on any buttons and don't do any calculation and then press on clear button, the value doesn't clear.
Do anyone have a soluation for it.

Ответить
reality inred
reality inred - 08.03.2023 17:40

so weak, not as calculators works.

Ответить
Waqar Ali
Waqar Ali - 08.03.2023 15:50

js code neither showing any output nor any error

Ответить
Aziz
Aziz - 02.03.2023 16:26

Thank you so much

Ответить
Danie Savage
Danie Savage - 21.02.2023 05:15

My equal function isn't working. Something isn't right in the JS. Can't figure out what:

(function() {

let screen = document.querySelector('.screen');
let buttons = document.querySelectorAll('.btn');
let clear = document.querySelector('.btn-clear');
let equal = document.querySelector('.btn-equal');

buttons.forEach(function(button) {
button.addEventListener('click', function(e) {
let value = e.target.dataset.num;
screen.value += value;
})
});
equal.addEventListener('click', function(e) {
if (screen.value === '') {
screen.value = "Please enter";
} else {
let answer = eval(screen.value);
screen.value = answer;
}
})
clear.addEventListener('click', function(e){ screen.value = "";
})
})();

Ответить
sonal@rana
sonal@rana - 20.02.2023 20:42

I find one problem in this calculator.. If any one type wrong no. Then.. There is no option to delete the value.. But overall calculator and teaching way is good.

Ответить
Jubair Ahamed
Jubair Ahamed - 19.02.2023 20:19

equal.addEventListener('click', function(e){
if (screen.value === ''){
screen.value = "";
} else{
let answer = eval(screen.value);
screen.value = answer;
}
})
// this set code is not working can you see it

Ответить
Yousef Nidal Mahdi
Yousef Nidal Mahdi - 19.02.2023 15:55

Perfect work mate!

Ответить
Danie Savage
Danie Savage - 17.02.2023 04:27

my box shadow isn't working. what did I do wrong:

.calculator {
width: 300px;
height: 500px;
box-shadow: 4px 4px 30px rgba(red, green, blue, alpha);
}

Ответить
Srimoyee Banerjee
Srimoyee Banerjee - 15.02.2023 19:16

please somebody describe what is the functionality of eval()

Ответить
NOTHING
NOTHING - 13.02.2023 21:59

can anyone tell me what's data-num in there ?

Ответить
Zena
Zena - 13.02.2023 14:16

Hi awesome tutorial. Can someone explain the data-num to me that's on html? I've been googling but still don't know why it's needed and why was it not needed for the equals and C buttons?

Ответить
Sanjan S Shetty
Sanjan S Shetty - 12.02.2023 12:52

If I press 042, the result is 34 .Its showing like this please resolve this.

Ответить
hithardh ksvln
hithardh ksvln - 07.02.2023 07:10

Excellent way of Teaching sir. While I was implementing I got to capture a bug/ improvisation for the calculator you built. After using '=' button, if you are clicking on any other button it has to clear the screen and take the input. One more idea is the screen should not take symbols(+,-,*,/) at the begging since we are simply using the eval() function of JS, we need such validations I guess:)

Ответить
Chiillybro
Chiillybro - 04.02.2023 18:59

super informative and thanks to comments for the undefined fix that was wierd

Ответить
Abhishek Mishra
Abhishek Mishra - 29.01.2023 17:34

Thanks you so much this video is really very helpful to practice the js code || Subscribed 😍

Ответить
BROZAM GENERAL
BROZAM GENERAL - 29.01.2023 13:25

Thanks for the simplified way of teaching, some complicate everything

Ответить
TRNGO TUBE
TRNGO TUBE - 28.01.2023 23:06

good but this calculator have some error because when we press the opretor more than one time it will add them multi times

Ответить