Sotodothat, wejusthad a linkherefirstdialoguesheetandyoujustthere a tripisgoingtobestylesthatCSSandweneedtotellthebrowserthatthiswas a stylishsheethere.
Sowhatwewanttodoisyouwannahave a singledid, whichisgoingtowrapeverythingandwe'regoingtogiveit a classhere, whichisgoingtosaycalculatorgrid, that's lowercasedandinsideofhere, we'regoingtoputourdifferentelements.
Thefirstthingthat I liketodoisselectalloverelements, includingourbeforeelementsandourafterelementsjustlikethis, I wanttochangetheboxsizeintotheborderbox, sothatwayit's easiertosizeorelements.
Also, I wanttosetourfunfamilyheresothatit's setonallofourdifferentowners.
Inthiscase, I'm goingtouse a fundcalledGothamRoundedwhichyoumaynothaveinstalledonyoursystem.
Soyoucanchooseanyfundthatyoulikethelookofandwewanttoapply a defaultfronttoefallbackontosoon.
Inourcase, we'rejustgoingtoselectthebodyelementandwe'regoingtofirstremoveallpaddingandmarginsothatourbackgroundfillsourentirescreenandthenwe'regoingtoapply a backgroundhere, soHere's thebackgroundkeywordandwewanttofly a winningingredient.
Didyouwanttomakesurethatourdisplayhereexcept a gridandwewanttojustifythecontentintothecenterofthescreenandwewanttoaligntheitemsintothissideofthescreen?
Ifweinput a verylargenumberhere, forexample, youcanseethatthisgrowstofitthatlargenumber.
Sowewannahavefirstthevalue, whichisgoingtobe a minmaxvalue, whichhasatminimum, wewantthistobe 100 and 20 pixelstall, butat a maximum, wewantittotheauto, whichessentiallysaysaslargeasitneedstobetofiteverything.
Andalso, I'm gonnachangethespacebetweento, sayspacearoundinsteadbecauseit'llpushourelements a littlebitclosertoeachotherand a littlefurtherawayfromthetopandbottomofthecontainer.
SoinsteadofdoingdocumentthatQueerSelectorallwe'regoingtousejustqueryselector, whichwillget a singleelementforusinsteadofmultipleagainwecansavedataequalscloseoffthatsquarebracket.
Wewanttodothis a bunchofothertimes.
Wewanttodoitforthedeletebuttonthatwehave.
Doitforallclearbuttonandofcourseweneedtogetourpreviousoperationandthisisnot a buttonthesexualtextelement.
We'rejustgoingtobecalled a calculator, andinsideofthisclass, we'regoingtoput a constructorwhichisgoingtotakealltheinputsforit, aswellasallthefunctionsforourcalculator.
Soareconstructedisessentiallyjustgoingtotake a previousoperationtextelementandourcurrentoperatetexthelmet.
The 1st 1 wementionedisclear, andthisisjustgoingtoclearoutourdifferentvariables.
Next, we'regoingtohaveourdeletefunctionforremoving a singlenumber.
We'regoingtocreate a functioncalledupendednumber, whichisessentiallywhat's goingtohappeneverysingletime a userclickson a numbertoaddtothescreenjustAsyouseeoverhere, youclick a numberanditaddsittothescreen.
Nextthingweneedtodoistohave a chooseoperationfunctionthistles.
What's goingtohappenanytime a userclicksononeoftheseoperationsoverhereandthisfunctionneedstotaketheparticularoperationthattheyuseyourselectedandsamethingwiththenumberfunction.
Wedidn't actuallypassthenumbertheuserselectedlasttwofunctionsthatweneedtohaveiswe'regonnahave a computerfunctionwhichisjustgoingtotakeourvaluesinsideofourcalculatorandcompute a singlevalueforwhatweneedtodisplayonthecalculator.
Andlastly, weneedtohave a functionthatallowsustheupdate.
Wecouldjustsetthisequaltoourthisdotcurrentoperatingjustlikethatandinsideofourpennumberinsteadofactuallyattendingthenumber, wecouldjustchangethecurrentofferand t pullthatnumber.
Now, ifwegooverourcalculatorhereandclickon a number, you'llseeitshowsupoverhere, andnomatterwhatnumberwecookon a littleshowupthere.
Andwhenwewon't clickonthis, wewantinsteadof a pendantnumber, wewanttochooseanoperation, andagain, we'rejustgoingtopassthetextoftheoperationthatwe'rechoosingandupdatethedisplayhereonoutupinourchooseoperationfunction, weneedtodo a littlebitoffancyandmath.
Ifwelookoverhere, clearoutallofthis.
Let's saywedid 22 a soonasweclickanoperation, youseethatthisgetsbroughtinto a previousoperatevalueanditclearsoutourcurrentoperationtobuild a typedin a newnumber.
Firstthingwedoiswewanttochangeourcurrentoperate, andwewanttosetitequaltoyourcurrentoperatinghereCurrents, copperandandall I wannadoisconvertthisto a stringandwewanttogettheverylastvaluefromthestringandchopitoff.
Andthisfunctionisjustgoingtoreturnthatnumberbutconvertedto a displayvaluefornow, we'lljustreturnthenumbergiventoit, andwe'regoingtocallthisfunctiondownhere.
Andthisfunctionisgoingtobe a littlebitcomplicated.
Wewantedfirsttomake a straightforwardversionofit, andthen I'llshowyousomeoftheproblemswiththat.
Thefirstthingthatwe'regoingtodobecauseyouwanttosetthisnumbertoanactualfloatsowecansayherewasgreat, a variablecalledfloatnumber, whichwouldhavesetthatequaltwopartsfloatofnumber.
Andthisisbecauseournumberisactuallystringandwewanttoconvertitto a numberfirst.
Thenwecansaythatifthefloatnumberisnot a number, ifthat's thecase, wecanjustreturnemptystrength.
Sincewedon't actuallyknowhowtoformatthisnumber, sinceit's not a number.
Thenifwedohave a number, wewanttosayReturnthenumbertwolocalestringnumberthattoolowcowstringandinsideofherewepassed a wellcow, whichisessentially a languageinourcase, wouldhaspassedEnglish.
AndifwesaythatGobertarchivegreaterhereandtypeout a longnumberwhonoticeit's notformatting, andthat's becauseweneedtomakesureweuseourfloatnumberdownhereinsteadofournormalnumber.
Sowewanttosayourmaximumfractiondigitsisgoingtobesetequaltozero, whichmeanstherecouldneverbeanydesperateplacesafterthisvaluewhenitgetsconvertedto a stringwith a bunchofcommerce, whichisperfectforourusecase.
Soitisputting a simpleelseherewillsay, Ifthisstoppreviousoperationsinyourtextelementhere, we'regoingtosetthisequalto 50 string.
Andnowifwesaythatandwedo a calculationjust a simpleoneequal, it'llemptyoutthatpreviousoperatevalueforusandleaveusonlywithourcurrentoperatevalue, whichisperfect.
Andwiththat, wehave a completelyfunctioningmodernJavaScriptcalculatorworkinginthebrowser.