Build this JS calculator in 15 minutes! 🖩

  Рет қаралды 762,900

Bro Code

Bro Code

Күн бұрын

Пікірлер: 526
@BroCodez
@BroCodez Жыл бұрын
IMPORTANT NOTE: eval() allows you to execute a string of code as if it were actual JavaScript code. While it is a useful tool, it is a security risk. I would recommend using eval() ONLY for learning purposes and not any actual production code. // CALCULATOR PROGRAM const display = document.getElementById("display"); function appendToDisplay(input){ display.value += input; } function clearDisplay(){ display.value = ""; } function calculate(){ try{ display.value = eval(display.value); } catch(error){ display.value = "Error"; } } Document + 7 8 9 - 4 5 6 * 1 2 3 / 0 . = C body{ margin: 0; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: hsl(0, 0%, 95%); } #calculator{ font-family: Arial, sans-serif; background-color: hsl(0, 0%, 15%); border-radius: 15px; max-width: 500px; overflow: hidden; } #display{ width: 100%; padding: 20px; font-size: 5rem; text-align: left; border: none; background-color: hsl(0, 0%, 20%); color: white; } #keys{ display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 25px; } button{ width: 100px; height: 100px; border-radius: 50px; border: none; background-color: hsl(0, 0%, 30%); color: white; font-size: 3rem; font-weight: bold; cursor: pointer; } button:hover{ background-color: hsl(0, 0%, 40%); } button:active{ background-color: hsl(0, 0%, 50%); } .operator-btn{ background-color: hsl(35, 100%, 55%); } .operator-btn:hover{ background-color: hsl(35, 100%, 65%); } .operator-btn:active{ background-color: hsl(35, 100%, 75%); }
@skappy2000
@skappy2000 Жыл бұрын
Hey bro code big fan here I was thinking will you make website projects using html, css and js? It will help a lot with people understanding more better in that way Portfolio-worthy projects
@mirmumit3888
@mirmumit3888 Жыл бұрын
Can u plz tell me, how to change the only color of the text "Error" on the calculator display?
@skappy2000
@skappy2000 Жыл бұрын
​@@mirmumit3888 Use the display.style.color property in script.js file function calculate(){ try{ display.value = eval(display.value); display.style.color = 'white'; // Set text color to white after successful calculation } catch(error){ display.value = "Error"; display.style.color = 'red'; // Set text color to red for error message } }
@SiiamW
@SiiamW Жыл бұрын
Hey clicking ''." more than once is an error too. this program is slightly wreaked.
@catempirecentral
@catempirecentral 11 ай бұрын
@@SiiamW well obviously, because 2..4 is not a valid float or integer
@alvinderama3196
@alvinderama3196 Жыл бұрын
Watching something being created from scratch is pretty entertaining and educational.
@realgoatzy
@realgoatzy 2 ай бұрын
don't you actually follow it or something?😂
@vc6218
@vc6218 9 ай бұрын
one of the few videos on here that breaks it down simply. I already understood a bit of html and css - javascript hasn't made that much sense to me until now. Thank you!
@Podlols
@Podlols 4 ай бұрын
sooo can you understand js now ??
@realgoatzy
@realgoatzy 2 ай бұрын
@@Podlols soon.
@Podlols
@Podlols 2 ай бұрын
@@realgoatzy now I can understand js
@realgoatzy
@realgoatzy 2 ай бұрын
@@Podlols nice btw I just started learning (like almost a week ago) myself
@syroxdxd
@syroxdxd 9 ай бұрын
I just have to say that you are amazing. I had an introduction class in java and I missed every lecture. I whatched the first 5 hours of your 12hr java course and I passed the exam. You are an amazing teacher. Better than the ones I have at univerity :)
@loosabway3400
@loosabway3400 5 ай бұрын
I'm a teacher and found this to be well-paced, explained in more detail where necessary without getting bogged down in stuff students can research for themselves, and fun. Well done.
@doronfeldman5152
@doronfeldman5152 Жыл бұрын
You have the best programming channel, I learn html, css, javascript and python in your channel
@SinmisolaJohnson
@SinmisolaJohnson 2 ай бұрын
That is crazy. Hope you practice daily.
@f4sma
@f4sma 9 ай бұрын
Your tone of the voice, the way you explain what you are doing.. it's perfect. Subbed!
@Prakash-i7y
@Prakash-i7y 6 ай бұрын
tk
@nergizken
@nergizken 2 ай бұрын
That was easily the most clear-cut project-guide I've come across. Though building a calc isn't rocket science but due to your explanation it was even more understandable! Thank you
@watchdoggie8145
@watchdoggie8145 10 ай бұрын
Super thankful for the awesome instructions! keep up the good work.
@dru_king7758
@dru_king7758 14 күн бұрын
I'm here in 2025 😄 , I love the way you teach BroCode. The video quality is clear, very clear and you teach very well such that beginners can understand.I hope you release more coding content of HTML, CSS, JS and other programming languages.
@chijiokeonyeagba7593
@chijiokeonyeagba7593 13 күн бұрын
finding it difficult to run the java after the display,clear and calculate functions.Any help?
@arjunpailoor4559
@arjunpailoor4559 4 ай бұрын
Thanks for this. a backspace button could be added,
@EthN_
@EthN_ 16 күн бұрын
This was a great intro to JavaScript. I made several mistakes along the way (mostly syntax) and got to debug it alone after several minutes of stressing. Great learning experience, thanks.
@AlexAraujo-o7
@AlexAraujo-o7 2 ай бұрын
Bro... You're simply the best teacher.... I was struggling with that, trying to do by myself, each function to do each calculation, and i just couldn't do it, then i just saw your video, and this eval() function and it just works, ty so much!
@pope1089
@pope1089 11 ай бұрын
Just started coding, That video helped alot. Straight to the point. I,ll have to check your other videos out before i start asking questions about eval() ans security risks. Thanks
@yateen-hi9er
@yateen-hi9er 10 ай бұрын
share some resorses with i am a beginner too
@ahmed-t4m8kx92
@ahmed-t4m8kx92 3 ай бұрын
​@@yateen-hi9er Sololearn or mimo for course(I'm not sure about mimo and sololearn is more popular, I use it too.) W3schools website, freecodecamp KZbin channel
@QxTrunkZ-fr7fg
@QxTrunkZ-fr7fg Ай бұрын
@@yateen-hi9er just get used to it, dont be shy and start ur own projects :D
@petersagan370
@petersagan370 7 ай бұрын
You shouldve added a function that prevents entry of another decimal point once it has been added to the display once. For example, once you enter 3.14, you cant add another decimal point until you enter an operator such that (3.14159.3123) wont be possible to enter in the display
@Nanashi_29
@Nanashi_29 10 ай бұрын
Best channel about programming
@RajagopallanV
@RajagopallanV 8 ай бұрын
After seeing other videos of writing the code for Calculator app, I find yours the best and easy to understand and needs less lines of code. Thank you very much for uploading this.
@DanielBrownsan
@DanielBrownsan 6 ай бұрын
Me: (Imagining 15-20 lines of code) Lesson: "One line using eval does it." I would be curious to see this done without eval. This feels like one of those, "Well, you CAN do it that way, but you shouldn't" situations. Great stuff!
@amineaheddare4918
@amineaheddare4918 5 ай бұрын
i did it and as a beginner it was a hell 😅
@gopal2919
@gopal2919 Ай бұрын
To complete evaluation,make sure how the regular calculator works and write js functions according to different situations which improves thinking ability
@sogwafl
@sogwafl Жыл бұрын
I have a terrible Java Professor, cant retain an oz of her teaching. So I exclusively built my own syllabus off your java topic vids and passed. You are doing gods work and are great at helping my dumbass retain all this info.
@ent.8979
@ent.8979 Жыл бұрын
youre not a dumbass, some teachers just don't know how to teach and make the subject impossible to understand. And that's mostly college professor. That's why learning from the internet is becoming more and more valid
@russellhan3534
@russellhan3534 Жыл бұрын
@@ent.8979facts, attending college literally for the degree
@lintee_12
@lintee_12 Жыл бұрын
@@ent.8979 i mean its probably because he was getting taught real programming fundamentals... he didn't even know that this was javascript not java
@shush5878
@shush5878 6 ай бұрын
bros prof is so bad he thought this was Java
@kelvinwilliams2908
@kelvinwilliams2908 Ай бұрын
I got this to work -but it took me a lot longer than 15 mins. However, I was very pleased with it. Well done - good video.
@reptilianis577
@reptilianis577 Жыл бұрын
Another useful video! I am waiting for more ;)
@Prakash-i7y
@Prakash-i7y 6 ай бұрын
supper
@He_Roll2024
@He_Roll2024 11 ай бұрын
Few codes but precised. I'm amazed bro.
@kasmkurtay5095
@kasmkurtay5095 Ай бұрын
I watched this video 4 times in a row , and i try to make the perfect exam as you did.. Finally i did my first JavaScript Project.. ThankYou BrocodeZ
@miladevs
@miladevs 8 ай бұрын
Awesome video! I love the clear explanations and the styling tips. Incorporating functional programming principles, like using pure functions, could further enhance the calculator’s logic. It would be interesting to see how this approach can make the code more concise and testable. Keep up the great work! 👍
@VictorLopezSoftware
@VictorLopezSoftware Ай бұрын
If anyone is having issues with their javascript not working make sure *the script runs before the DOM is fully loaded* - In other words if you are pressing the buttons but nothing loads: Add 'defer' attribute to your script tag in your .html file (). This attribute allows the elimination of parser-blocking javascript, where the browser would have to load and evaluate scripts before continuing to parse. This fixed it for me.
@QxTrunkZ-fr7fg
@QxTrunkZ-fr7fg Ай бұрын
underrated comment
@Andrew-y7l
@Andrew-y7l Жыл бұрын
I think this was the easiest calculator build and explanation from any other youtube channel
@samueldayo9261
@samueldayo9261 Жыл бұрын
Was about to comment this yesterday it is the best
@bama2619
@bama2619 3 ай бұрын
never thought it could be that easy, thank you for the explanation
@Azufunnycomedy
@Azufunnycomedy 2 ай бұрын
one of the best designs i have ever seen
@petersimthobele
@petersimthobele 10 ай бұрын
I learnt a lot from this video in 15 min 👏👌
@sovereignlivingsoul
@sovereignlivingsoul 20 күн бұрын
i think that is the simplest calculator program i have seen so far, i added the Modulus Operator, thanks for sharing and God Bless
@omniman8912
@omniman8912 Ай бұрын
Wouldn't even imagine if making calculator was that easy. Thank you
@levon9
@levon9 8 ай бұрын
Wow .. FANTASTIC - thank you so much for this. Going to look for other videos like this from you. (also subscribed :)
@ritechaserious
@ritechaserious 6 ай бұрын
sir i loved it. It helped a lot in confidence building as a beginner
@mohamedahsan4710
@mohamedahsan4710 6 ай бұрын
Bro deserves recognition!!!!
@0cactus
@0cactus 6 ай бұрын
Thanks, I know a little JavaScript, but unable to build beautiful design in html with css. Now I understood some interesting conceptions about css styling and feel ready to learn css.
@armandopena5508
@armandopena5508 10 ай бұрын
I was hopping to see how you made the actual calculation taking into account that eval is not safe, it would be awesome if you could share how to make a function that at least calculates some basic mathematical operations since this is a very basic project that many people who are starting in programming make, usually without adding the funcitonality, when parsing the math operation is the most important thing of this project!. Great content!
@shjsbsbs7186
@shjsbsbs7186 10 ай бұрын
Agree, eval is not safe for newbie
@larslover6559
@larslover6559 10 ай бұрын
Theres several nice tutorial on python to make calculator without the eval function. There you really see it hard coded from scractch!
@habibousy8723
@habibousy8723 8 ай бұрын
GREAT I'm senegalese and my english is not perfect but I learn a lot because of you😎😎😎. My javascript futur will be bright with you😎😎
@geoffreyjbrown
@geoffreyjbrown Ай бұрын
Very helpful showing the operation of html, javascript and css.
@RashmiPai-ru4br
@RashmiPai-ru4br 15 күн бұрын
Very useful for my miniproject🥰🙏
@piotrmazgaj
@piotrmazgaj 6 ай бұрын
This is my seal. I have watched the entire video, understood it, and I can explain it in my own words, thus I have gained knowledge. This is my seal.
@bennymeister
@bennymeister 6 ай бұрын
this is my seal 🦭
@zxot14
@zxot14 9 ай бұрын
I don't understand code that well but something about his videos is just so therapeutic.
@Miko-kc9td
@Miko-kc9td 4 ай бұрын
Awesome, clear instructions and straigth to the point.
@muhammet_05
@muhammet_05 Жыл бұрын
Thanks for those teaching video. i love it ❤
@Zahraalishahan
@Zahraalishahan 7 ай бұрын
woow! easiest way to create a calculator..i did it because ov u..thankuu so much:)
@Econ-man2060
@Econ-man2060 5 күн бұрын
Cool rudimentary stuff... Is there where you can add a little bit of advance calculator
@artisticmohan5544
@artisticmohan5544 5 ай бұрын
Thanks Mate. Really helped with my project.
@Alauddindipu
@Alauddindipu 6 ай бұрын
Excellent. In short, you did a lot!
@naglakandeel3152
@naglakandeel3152 10 ай бұрын
best teacher ever continue ❤
@AnointingOlabode
@AnointingOlabode 2 ай бұрын
Nice one bro code it`s so easy to grab from you Thank you 🥳🤩
@hurricanos13
@hurricanos13 Жыл бұрын
One of the best coding channel aside with the legendary new boston Bucky Roberts. but i think this channel stuff is also hated by youtube algorithms
@hariharasudhans7828
@hariharasudhans7828 5 ай бұрын
Definitely Impressive🤩🤩
@aminahshentour8002
@aminahshentour8002 8 ай бұрын
Never understood JS as much as i did now. I am a loyal fan. Thank you
@abhisasmal271
@abhisasmal271 3 ай бұрын
U can also make it a typable one by removing the 'readonly'. Its easier then just clicking buttons
@Fas832-f8r
@Fas832-f8r Ай бұрын
great work 👍
@JibinSajuJoseph
@JibinSajuJoseph 3 ай бұрын
Awesome! I noticed when display.value is “Error” then input is appended to it (e.g., “Error123”). Fix: function appendToDisplay(input) { if (display.value == "Error") { clearDisplay(); display.value += input; } else { display.value += input; } }
@haytham30000
@haytham30000 5 сағат бұрын
thanks man😀😃
@12karmel12
@12karmel12 Жыл бұрын
thank you for making daily javascript videos
@esatkurtul451
@esatkurtul451 2 ай бұрын
you can use button:nth-child(4n-3) { background-color: hsl(39, 100%, 50%); } instead of .operator-btn class
@SamialFardin
@SamialFardin 5 ай бұрын
Thanks you so much bro ❤❤ Keep it DOING ❤❤❤❤
@niyonkuruinnocent17
@niyonkuruinnocent17 10 ай бұрын
You're the best teacher ❤
@elisabethkolar9364
@elisabethkolar9364 10 ай бұрын
super cool, thank's a lot
@TheRealKingofCubing
@TheRealKingofCubing 10 ай бұрын
This is teaching me so much amazing video
@mohsenvanc
@mohsenvanc 9 ай бұрын
that is amazing, thank you
@PrimordialzBS
@PrimordialzBS 2 ай бұрын
11months later and still helped 👍. but the js doesn't work and i've re written it 4 times 😢
@Aim00108
@Aim00108 7 ай бұрын
thank you bro for introducing me with "value" method
@jacksondidas9403
@jacksondidas9403 6 ай бұрын
Thank you very much, I understand and it helped me a lot
@volinh6386
@volinh6386 Жыл бұрын
your style' css so good , it very butufu
@kingshahzad78
@kingshahzad78 5 ай бұрын
Outstanding❤
@Newbtube92
@Newbtube92 8 ай бұрын
Great tutorial!
@Sarat0101
@Sarat0101 2 ай бұрын
Thank youu❤❤
@venug2617
@venug2617 7 ай бұрын
Beautiful presentation.....
@XilqaXilqa
@XilqaXilqa Ай бұрын
😂damm that's easy and 😎 cool it takes longer to style 😂 I never used eval in any project before you rock bro...🎉
@Vinayadari
@Vinayadari 2 ай бұрын
function clearonebit() { display.value = display.value.slice(0, -1); } we can add new button to remove onebit
@hunters1212
@hunters1212 6 ай бұрын
Really nice explanation
@samikshakittur1078
@samikshakittur1078 4 ай бұрын
Thank you so much!!
@ChristianChinakuezeofficial
@ChristianChinakuezeofficial 4 ай бұрын
Nice tutorial sir
@jiyoungkim9258
@jiyoungkim9258 Жыл бұрын
you literally give me confidence
@pratyushmishra77
@pratyushmishra77 5 ай бұрын
Thanks bro 🙌
@Oh_Sayang
@Oh_Sayang Жыл бұрын
Now my iPad can finally have a calculator app lol
@BaljinderKaur-hd4dj
@BaljinderKaur-hd4dj 8 ай бұрын
really helpful. Thanks a lot
@PyTechUz
@PyTechUz 5 ай бұрын
bro thank you 👍
@namanthacker
@namanthacker 10 ай бұрын
Very nice video Thanks!!
@khushantwankhede8311
@khushantwankhede8311 11 ай бұрын
thankyou for such a useful content.
@cheaterlp23
@cheaterlp23 9 ай бұрын
My version didn't work, so I searched for a while. Guess what the error was. Correct: My version: =_= Anyway, really useful video, learned a lot.
@hunin27
@hunin27 Жыл бұрын
Wow, then what we are doing is pretty much just styling. I had no idea javascript had a "built-in" calculator inside of a function!!
@BroCodez
@BroCodez Жыл бұрын
eval() runs a JS expression dynamically at runtime. It can be a security risk tho
@hunin27
@hunin27 Жыл бұрын
oh, well im pretty sure its not that hard to make a calculator without using it. i mean eval is a function and we could just recreate it@@BroCodez
@QuantumCanvas07
@QuantumCanvas07 Жыл бұрын
You can have 100 years of JS experience but still be encountering something damn new 💀 Just a beauty of coding
@bhaveshjadav804
@bhaveshjadav804 5 ай бұрын
@@BroCodez hey bro there is a error in this code when i click any mathematical sign(+,-,*,/) more that 2 time it display on the screen . for example if i click + button 2 times then it display 2 time like this (2++2) ,please solve this error
@daeltam
@daeltam 2 ай бұрын
@@bhaveshjadav804 That's not an error in the way that you can print whatever you want on the display there is no limit, same thing for . we can write 3.1415.926 which is not correct. It would need some checking that i don't know how to do.
@sandippandey9181
@sandippandey9181 6 ай бұрын
Pretty Awesome !done
@wonders8410
@wonders8410 9 ай бұрын
Hey just want to let you know that there is an error in the code that you have presented if you do 7+ =you know it equals an error but that error is a text and you can do something like Error + 7 = FUNCTION ERROR() {[NATIVE CODE]}
@kenmakozume5393
@kenmakozume5393 Ай бұрын
thank you so much.
@neerajmeka25
@neerajmeka25 11 ай бұрын
Great Project had fun to build this project, u got a new sub will check your more videos
@paraglide01
@paraglide01 Жыл бұрын
Wauw, thanks man this is great. Making a calculator creates so many ideas for apps that need input and calculating.
@Zaynahazlanworld
@Zaynahazlanworld 8 ай бұрын
thanku .i hv done some typo mistake ,but handle it through chatgpt.thanks for the code
@MufareezMMM
@MufareezMMM 2 ай бұрын
best ... one . thank you
@mmafights__
@mmafights__ 11 ай бұрын
soooooo useful thankssssss❤❤
@shrawanigulkari4739
@shrawanigulkari4739 Күн бұрын
okay...video is amazing, no doubt. Umm but anybody else who's calculator looked different from what was shown??
@MariaMutima-s6c
@MariaMutima-s6c 4 ай бұрын
Very much for every developer
@chillguy_uz
@chillguy_uz 10 ай бұрын
So educational video ever seen
@coderprakash
@coderprakash Жыл бұрын
Hi please make a complete tutorial on typescript 🙏 i followed ur javascript and react thanks alot ❤️🔥 love from India, I know Frontend development because of u please consider my request and make typescript full tutorial
@fuzakhozs7783
@fuzakhozs7783 5 ай бұрын
Impressive❤
@siampro3891
@siampro3891 Жыл бұрын
BEST👍👍👍👍
@kursatepik5197
@kursatepik5197 Жыл бұрын
you are a hero brother
The JavaScript DOM explained in 5 minutes! 🌳
5:01
Bro Code
Рет қаралды 169 М.
Login Form in HTML & CSS
11:07
Codehal
Рет қаралды 1,9 МЛН
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
Web Development Roadmap 2025 with GenAI
19:21
Chai aur Code
Рет қаралды 226 М.
20 Programming Projects That Will Make You A God At Coding
14:27
The Coding Sloth
Рет қаралды 1,7 МЛН
How is this Website so fast!?
13:39
Wes Bos
Рет қаралды 1,3 МЛН
Learn DOM Navigation in 15 minutes! 🧭
15:27
Bro Code
Рет қаралды 19 М.
ASMR Programming - Spinning Cube - No Talking
20:45
Servet Gulnaroglu
Рет қаралды 4,4 МЛН
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
I Beat Minecraft From One Grass Block
35:27
Beppo
Рет қаралды 7 МЛН
How to OVER Engineer a Website // What is a Tech Stack?
11:20
Fireship
Рет қаралды 2,6 МЛН
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 854 М.
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН