JavaScript Project | Build Simple Calculator With JavaScript HTML CSS

JavaScript Project | Build Simple Calculator With JavaScript HTML CSS

Tech2 etc

3 года назад

210,441 Просмотров

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


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

@ourmaths8293
@ourmaths8293 - 16.05.2024 09:01

thanks it worked, I removed btn class from = and C.

Ответить
@AFTROGAME
@AFTROGAME - 14.04.2024 20:40

Please answer or explain why equal is not working, I'm waiting!

Ответить
@pias-art-music
@pias-art-music - 21.03.2024 21:48

I am getting an error which says buttons.forEach is not a function

Ответить
@emmanueloluwadamilolaajala225
@emmanueloluwadamilolaajala225 - 12.03.2024 16:50

This is nice but I'm having a problem here. My own calculator didn't give me the answer whenever I want to calculate. It keeps saying undefined and I followed all what you said in this video

Ответить
@frankkuper9861
@frankkuper9861 - 19.02.2024 16:29

Nice vid, thanks!

Ответить
@ChefnCoder
@ChefnCoder - 28.01.2024 11:27

really awesome explanation of each line, took me just an hour to finish up and code too

Ответить
@mrrobot4504
@mrrobot4504 - 30.11.2023 18:58

Great video 🙏🙏

Ответить
@suryanathchakrabarti530
@suryanathchakrabarti530 - 29.10.2023 23:47

How to use enter keyas a equal button...can someone help please?

Ответить
@somachakrabarti2060
@somachakrabarti2060 - 29.10.2023 19:43

It is saying document is not defined

Ответить
@arvinbonggal5443
@arvinbonggal5443 - 16.10.2023 04:41

Greate tutorial! I learned a lot specially on debugging the code as I encountered an issue with regards to button function, I have added additional class to yellow and gray button which is crucial for calculating value and excluded equals and clear as they don't have value so during button click i don't get undefined when I click equals and clear.

Ответить
@mahpara8171
@mahpara8171 - 10.10.2023 15:19

thank you

Ответить
@panzagamesplay902
@panzagamesplay902 - 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 ?

Ответить
@ShivamKumar-dg8zp
@ShivamKumar-dg8zp - 27.08.2023 19:29

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

Ответить
@AdityaG.
@AdityaG. - 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...

Ответить
@lakshyasing
@lakshyasing - 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 = "";
})
})();

Ответить
@radheradhedigonto
@radheradhedigonto - 14.08.2023 19:34

bro 4*4undefine plz fix this problem

Ответить
@ajaydevgan24
@ajaydevgan24 - 07.08.2023 14:21

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

Ответить
@stephengichia154
@stephengichia154 - 31.07.2023 09:44

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

Ответить
@victoriaazola6409
@victoriaazola6409 - 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
}
})

Ответить
@tanzeelaghafoor5210
@tanzeelaghafoor5210 - 25.06.2023 10:55

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

Ответить
@awatekeerthi6239
@awatekeerthi6239 - 23.06.2023 18:33

Thank you🎉

Ответить
@Nepc_explains
@Nepc_explains - 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

Ответить
@princekaushikk
@princekaushikk - 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.

Ответить
@MohitKumar-jy6hf
@MohitKumar-jy6hf - 23.05.2023 19:48

Amazing knowledge about front end

Ответить
@amenetefia3213
@amenetefia3213 - 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

Ответить
@1989SeanSmith
@1989SeanSmith - 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

Ответить
@aritnath151
@aritnath151 - 24.04.2023 18:39

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

Ответить
@abhaynarayan4114
@abhaynarayan4114 - 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;
})
});


})();

Ответить
@xenonebanihal3979
@xenonebanihal3979 - 16.04.2023 10:26

equal button is showing undefined in screen.value
pl guide

Ответить
@debadey8614
@debadey8614 - 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!!

Ответить
@ryanboland7307
@ryanboland7307 - 13.04.2023 22:49

8.03

Ответить
@CommanderKurn
@CommanderKurn - 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

Ответить
@sahiraahamed
@sahiraahamed - 10.04.2023 17:29

Alhamdulillah.. Understood👏

Ответить
@Chandraprakash-kx4ic
@Chandraprakash-kx4ic - 30.03.2023 19:42

❤Thanku so much Bhai ❤

Ответить
@MathSCSil
@MathSCSil - 30.03.2023 17:58

Thank you for this playlist

Ответить
@liamaiken1782
@liamaiken1782 - 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.

Ответить
@nakedsnake_2128
@nakedsnake_2128 - 22.03.2023 23:21

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

Ответить
@Ankushmehra0411
@Ankushmehra0411 - 21.03.2023 12:29

how to set input limit ?

Ответить
@animezone6091
@animezone6091 - 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.

Ответить
@riturajpathak1905
@riturajpathak1905 - 17.03.2023 18:07

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

Ответить
@clarisseaguirre6161
@clarisseaguirre6161 - 14.03.2023 17:10

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

🤧

Ответить
@mohamedahmed-ct9td
@mohamedahmed-ct9td - 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.

Ответить
@realityinred
@realityinred - 08.03.2023 17:40

so weak, not as calculators works.

Ответить
@waqarali191
@waqarali191 - 08.03.2023 15:50

js code neither showing any output nor any error

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

Thank you so much

Ответить
@daniesavage
@daniesavage - 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 = "";
})
})();

Ответить
@Ishablogs1
@Ishablogs1 - 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.

Ответить