Simple Weight Converter App With JavaScript & Bootstrap 4

Поділитися
Вставка
  • Опубліковано 12 вер 2024
  • In this mini-project tutorial we will be building a simple weight converter app using JavaScript and Bootstrap 4 for the ui. It will convert pounds to grams, kilograms and ounces. This will be pure vanilla JavaScript with no JS libraries or frameworks.
    CODE: Code for this project
    codepen.io/bra...
    BECOME A PATRON: Get special perks
    / traversymedia
    ONE TIME DONATIONS:
    www.paypal.me/t...
    FOLLOW TRAVERSY MEDIA:
    / traversymedia
    / traversymedia
    / traversymedia
    COURSES & MORE INFO:
    www.traversymed...

КОМЕНТАРІ • 336

  • @inponderland
    @inponderland 6 років тому +277

    For people using the newest version of bootstrap, the classes to color the cards are 'bg-primary' , 'bg-success', and 'bg-danger'. They have done away with the 'card-success', etc. variants of the background classes.

    • @MrLuke3456
      @MrLuke3456 6 років тому +9

      Thanks a lot! I spent a good couple of minutes trying to figure out what I was doing wrong.

    • @MrLuke3456
      @MrLuke3456 6 років тому +2

      Thanks for the info! I helped my find what I was doing wrong.

    • @juthisarkeraka6336
      @juthisarkeraka6336 6 років тому +2

      thnks for the info! :D

    • @alexraab3022
      @alexraab3022 6 років тому +1

      Thank you

    • @sharifabahar6257
      @sharifabahar6257 6 років тому +2

      tnqs a lot for ur useful command.

  • @aleferr3ira
    @aleferr3ira 7 років тому +104

    Great tutorial!!
    For those who want to keep only two decimals:
    document.getElementById('gramsOutput').innerHTML = (lbs / 0.0022046).toFixed(2);
    document.getElementById('kgOutput').innerHTML = (lbs / 2.2046).toFixed(2);

    • @zmOe1
      @zmOe1 7 років тому

      thx

    • @MayankSingh-lg5wx
      @MayankSingh-lg5wx 7 років тому +5

      Alessandra Souza another way by using math.floor()

    • @aleferr3ira
      @aleferr3ira 7 років тому

      thanks, Mayank Singh!

    • @caroldanvers265
      @caroldanvers265 6 років тому

      good try but I still get a null value

  • @jorjlm83
    @jorjlm83 6 років тому +47

    For those doing this tutorial most recently, I believe there were some naming changes for bootstrap classes, so, the visual end result in some parts might not be the same. This padding on each card (Grams, Kilograms and Ounces) wasn't working, so I tried replacing by class="card-body" instead of "card-block" and it works.

    • @kingberz
      @kingberz 5 років тому

      geez thanks... i thought i was doing something wrong all the way xD

  • @stancedtaco
    @stancedtaco 6 років тому +40

    For anyone using the latest version of BS4, to get the colored background of the cards to display, change "card-danger" to "bg-danger" same goes with the other cards as well.

    • @gabytzugabytzu16
      @gabytzugabytzu16 6 років тому +2

      Thank you, man! You should go to the top with this comment. I scratched my head for like 5 minutes not knowing why tf my cards don't get the colored background. :))

    • @balance_andbliss
      @balance_andbliss 5 років тому

      And also card-body instead of card-block

    • @bhavin7485
      @bhavin7485 5 років тому

      Same here..@@gabytzugabytzu16

    • @bhavin7485
      @bhavin7485 5 років тому

      Thanks man...

    • @kingberz
      @kingberz 5 років тому

      @@gabytzugabytzu16yehh when are they going to be consistent all through

  • @m.magdalena
    @m.magdalena 7 років тому +64

    Homework delivery temperature converter style! codepen.io/m2creates/full/prvqjp/

    •  7 років тому

      Melanie awesome work combining two tutorials. :) Can you do with a dropdown list for selecting initial input?

    • @TraversyMedia
      @TraversyMedia  7 років тому +4

      Awesome Melanie! Just awesome. Thanks for sharing

    • @m.magdalena
      @m.magdalena 7 років тому +1

      Strahinja Živković I thought about that but couldn't quite figure out how to dynamically fill just two output boxes (and having a drop-down with 6 output boxes seemed silly). Perhaps I'll poke it more today and see what I come up with!

    • @m.magdalena
      @m.magdalena 7 років тому +2

      Traversy Media thanks for the fun assignment that made practicing JS fun!

    • @tylerzey1229
      @tylerzey1229 7 років тому

      i know you.

  • @onecarwood
    @onecarwood 7 років тому +118

    This will come in handy for weed conversions

  • @efs76media
    @efs76media 7 років тому +1

    By a mile and a half, you are by far the best tutor on UA-cam. Thank you so much for your videos and sharing your knowledge. Awesome stuff! :)

  • @cesarlara3974
    @cesarlara3974 7 років тому +33

    CAN YOU DO A VIDEO ON HOW TO DO A PORTFOLIO FOR BEGINNERS?

  • @CodingPhase
    @CodingPhase 7 років тому +1

    This is a great quick tutorial for people to get their practice. Nice Job!!! Love seeing you in the video more!!!

  • @subvice2593
    @subvice2593 5 років тому +2

    This is a great tutorial. I am starting to build some real fluency with vanilla js concepts after this. Love the homework idea as well, going to try my hand at it for sure. Thanks for all the amazing content, Brad.

  • @pickandhoop
    @pickandhoop 5 років тому +2

    Great Work Brad. Clear, fast and simple. As usual. Keep them coming!

  • @tnmando
    @tnmando 6 років тому +1

    Just getting started with JS, but I really like the assignment idea. As a beginner it is great to see the different ways people approached the task.

  • @cherulast7998
    @cherulast7998 4 роки тому +4

    Hey brad u know that thousnds students are using ur tutorials i like ur small projects it gives me some idea how to work practically

  • @obedientzombie3080
    @obedientzombie3080 7 років тому +17

    This stuff is really good. Got no money to be a paetron, so here's a thubs up.

  • @GAVIGHUMMAN
    @GAVIGHUMMAN 6 років тому +10

    With current bootstrap 4 cdn version "card card-primary" is now "card bg-primary". for future viewers

  • @praveenbadigerv
    @praveenbadigerv 7 років тому +3

    Short and simple yet so many things to learn. Thanks Brad. 🙌

  • @sangamadhikari8497
    @sangamadhikari8497 7 років тому +15

    Vanilla way of programming is ❤

  • @suatarancak7206
    @suatarancak7206 4 роки тому +1

    weight converter tools online : calculatorsnew.com/content/weight-converter/104

  • @vaibhavmor1868
    @vaibhavmor1868 7 років тому +1

    Thanks @Travery Media! Keep these small projects coming!

  • @bardhan.abhirup
    @bardhan.abhirup 6 років тому +2

    Thanks a ton for your content! this stuff has been really helpful. I've been binging on your tutorials!

  • @jinhoshin7923
    @jinhoshin7923 5 років тому +4

    card-primary, card-success and card-danger has changed to bg-primay, bg-success, and bg-danger currently. Also change card-block to "card-body" will look much more like his work.

    • @radiclelife
      @radiclelife 5 років тому

      I went with card-header to make the blocks a little skinnier. The card-body was too fat for me. Either way, it'll work!

  • @M3TALISB3AST
    @M3TALISB3AST 7 років тому +1

    Do more of these I'm really digging these vanilla JavaScript projects.

  • @busyrand
    @busyrand 7 років тому +1

    Thank you so much for making this Very Beginner Friendly! I really appreciate your explanations.

  • @ronaldjohnson4470
    @ronaldjohnson4470 7 років тому +3

    Very nice tutorial Brad, thank you.

  • @stevankostadinovic2250
    @stevankostadinovic2250 7 років тому

    I like how you are making app which looks good and not just text output on white background like in many other tutorials. I would like to see tutorial for currency converter with use of external api for getting current conversion rates, so it is always up to date.

  • @Suneriins234
    @Suneriins234 4 роки тому +1

    Weight Converter









    Grames





    Kilogrames





    Ounces





    '
    document.getElementById('output').style.visibility = 'hidden';
    document.getElementById('IbsInput').addEventListener('input', function(e){
    document.getElementById('output').style.visibility = 'visible';
    let Ibs = e.target.value;
    document.getElementById('gramsOutput').innerHTML = Ibs/0.0022045;
    document.getElementById('kgOutput').innerHTML = Ibs/2.2046;
    document.getElementById('ozOutput').innerHTML = Ibs*16;
    });

  • @lukkash
    @lukkash 3 роки тому

    or with any framework you can make a converter (e.g. pounds, grams, ounces, troy ounces) where all other fields recalculate themselves when you input a number into one of them.
    A Converter is a quite interesting project when you start learning frameworks.

  • @andreaskaaej
    @andreaskaaej 2 роки тому

    Short and concise video, great explanations. Thanks 👍🏼

  • @glennkey3461
    @glennkey3461 4 роки тому

    card-primary etc. is now bg-primary on bootsrap, for those wondering

  • @lukkash
    @lukkash 3 роки тому

    Additionally formatting with toFixed and also names on the left and values on the right. I love converter projects :)

  • @daviskane7904
    @daviskane7904 6 років тому

    Thanks Brad - another dope tutorial where I learned a ton!

  • @projectDominic
    @projectDominic 6 років тому

    Great practice changing some of the classes from alpha Bootstrap to 4.1 and of course they were already pointed out in the comments! Also used some mx-auto from Brad's Bootstrap course Leaving background white looks better

  • @MushaGH
    @MushaGH 7 років тому +1

    you make me fall in love with web development

  • @lawrencenkadi8926
    @lawrencenkadi8926 5 років тому

    That was very helpful for a beginner like me. It was very clear and easy to follow. Yeah! I'm happy with that. Thank you

  • @medi7573
    @medi7573 7 років тому

    This is it bro it is alot better now please make all next tutorials same way i mean live reloading and split screnn into two parts like this we can see what is created on the page while you are typing :D

  • @rufus9821
    @rufus9821 7 років тому

    awesome vid as usual. best 17 minutes i have spent

  • @FULLUPE1
    @FULLUPE1 4 роки тому

    Thanks so much it was a great tutorial .. i'm a beginner of js ...have added little to this which is " when lbs == 0 then the output is hidden again " thanks once again

  • @MrDTTV
    @MrDTTV 7 років тому

    this was awesome! keep the content coming!

  • @sigplayer112
    @sigplayer112 5 років тому

    you can add
    if(document.getElementById('lbsInput').value.length === 0){
    document.getElementById('output').style.visibility = 'hidden';
    }
    to hide it from displaying zeros if input is empty

    • @justdarkjazz4020
      @justdarkjazz4020 5 років тому

      Add it where exactly? I tried it and it kind of fucked up my code.

  • @haroldw2823
    @haroldw2823 7 років тому

    Nice Job Mate, easy to follow

  • @pikachu5223
    @pikachu5223 7 років тому +6

    Thanks Brad! Love you

  • @dndnegy73
    @dndnegy73 5 років тому

    finally I made simple app even if its a small one it worked and the bigger to come

  • @lulualmohtarif
    @lulualmohtarif 7 років тому

    thanks alot brad, that was so great and clear
    from morroco

  • @dxdMyBroadcast
    @dxdMyBroadcast 7 років тому

    Nice one)
    I'd add a check for typeof === 'number' and error handling.

    • @dusski1
      @dusski1 7 років тому

      You don't need that because you're using a number input.

  • @skrezwan12
    @skrezwan12 5 років тому +1

    Good for practicing Js and bootstrap as well.

  • @al-yasa
    @al-yasa 7 років тому

    Here's the homework: i made two versions.
    options version:
    codepen.io/Al-Yasa/full/OjJVrK
    checkbox version:
    codepen.io/Al-Yasa/full/GvRJBe

  • @phethomberg9669
    @phethomberg9669 6 років тому

    Awesome video man !! Pls do more this type of video

  • @0the0ambient0
    @0the0ambient0 7 років тому

    As always, great tutorial

  • @Vlusion
    @Vlusion 7 років тому

    Was in coding spree so picked a new 'coding theme' screensaver. Same like your banner I now see :)

  • @CreatingAlong
    @CreatingAlong 4 роки тому +2

    I thought I might mention "e.target.value" returns an error, had to change it to "event.target.value" to get an output.

  • @azizatawfiq828
    @azizatawfiq828 4 роки тому

    very nice tutorial ..thanks alot

  • @sdborn8667
    @sdborn8667 7 років тому

    Thank you, Brad! Nice video!

  • @americomondragon6973
    @americomondragon6973 3 роки тому

    Excelente video, es el mas sencillo que he econtrado, muchas gracias!

  • @GilFavor101
    @GilFavor101 4 роки тому

    Only thing wrong with this video is that there isn't a link in the description for another video just like this : ) Great video here, thanks for doing this.

  • @JBuchmann
    @JBuchmann 7 років тому

    Great tutorial, thanks! I think it would be cool if you could show how to do the same/similar app in multiple technologies... for example Angular, React, and others (this vid is already vanilla js). It would be valuable to see the different approaches to the same problems in each technology.

  • @medhamohanty5270
    @medhamohanty5270 3 роки тому

    Great informative video. Very helpful.

  • @ThisIsJ0nny
    @ThisIsJ0nny 7 років тому

    Hey man, would be great to get your opinion / some tutorials on sails. Keep up the awesome work!
    (Also love the clicky keyboard, not to loud, not too quiet)

    • @TraversyMedia
      @TraversyMedia  7 років тому

      Thanks. It is actually one of the quieter ones I could find. I tend to smash the keys when I code. Off video I use a cherry mx red switch mechanical keyboard but it is way too loud for recording

  • @hirephpdevelopers3840
    @hirephpdevelopers3840 7 років тому

    Very informative tutorial Brad, thank you.

  • @inponderland
    @inponderland 6 років тому

    *homework submission:* codepen.io/csbrown/full/goaKWX
    (the div and values reset after each button click, to minimize confusing UI)

  • @scottyhall4215
    @scottyhall4215 5 років тому +1

    I do wish you would slow down some for those that cannot type so fast and are trying to learn. Keep in mind you are teaching people and it would be nice to breathe every now and then and take in what has been done. Otherwise I might as well just copy and paste and be done with it.

  • @simplex2168
    @simplex2168 6 років тому +1

    For the people who are getting stuck at the colors: The bootstrap class has been changed to bg-primary not card-primary.

  • @PythonicPath1
    @PythonicPath1 4 роки тому +1

    My code for converting all weights : github.com/Azzam49/weight_convertor

  • @joydas1685
    @joydas1685 7 років тому

    Good video ;)
    got some knowledge regarding bootstrap and javascript

  • @dineshrout2527
    @dineshrout2527 4 роки тому

    This was not a difficult project, but your teaching made it interesting. I'm going to make it in css now.🙂

  • @PoetrifidSoul
    @PoetrifidSoul 4 роки тому

    Thanks a lot gentleman :)

  • @kaktotak547
    @kaktotak547 5 років тому

    Your videos are great!

  • @ghnanax
    @ghnanax 7 років тому

    Hello Brad. Would you recommend windows over mac? I know Mac is the most sort after due to Linux etc. However, since you are knowledgeable in a number of languages what's your take on this? Thank you.

  • @FlashMoney-ps8ef
    @FlashMoney-ps8ef Рік тому

    Great tutorial, I would like to know how to make with cross-references , in order that when I set the value of the ounces (or the kilograms or grams) the program gives me the original pounds value as well... Thanks for this video

  • @galbalazs87
    @galbalazs87 7 років тому

    Awesome, as always! Thanks!! :)

  • @matteolinux9467
    @matteolinux9467 7 років тому

    very clear and nice video! thanks

  • @rymbouchetara1066
    @rymbouchetara1066 5 років тому

    Cam SB said : "For people using the newest version of bootstrap, the classes to color the cards are 'bg-primary' , 'bg-success', and 'bg-danger'. They have done away with the 'card-success', etc. variants of the background classes." Also for card-block use card-body !

  • @bryanbolanos6557
    @bryanbolanos6557 7 років тому

    Awesome tutorial!!

  • @moycs777
    @moycs777 7 років тому

    Very good exampleee, thanx!

  • @nagahumanbeingzooofparticl8836
    @nagahumanbeingzooofparticl8836 6 років тому

    Thank you so Much Brad..🥇🥇🥇

  • @randombiketrips3296
    @randombiketrips3296 7 років тому

    Is there a reason why you use Atom as opposed to VSC or Sublime? I really like the way you teach because it's really clear and simple, btw.

  • @brokiama
    @brokiama 7 років тому +1

    Will you make a JS crash course? Didnt see it in your channel, you're a great teacher BTW.

    • @TraversyMedia
      @TraversyMedia  7 років тому +8

      I have a JavaScript Fundamentals video but I will be doing an updated one soon

  • @samshanmukh
    @samshanmukh 7 років тому

    nice idea of giving homework for community.

  • @RABWA333
    @RABWA333 7 років тому

    Thanks, nice video , informative 👍

  • @mrgreggles998
    @mrgreggles998 7 років тому

    This is great; interesting to see you use Bootstrap 4. Hopefully it'll be operational in the foreseeable future.
    Brad, any specific reasons why you use Atom over Visual Studio Code?

    • @TraversyMedia
      @TraversyMedia  7 років тому +4

      Honestly Gregg, I love both and I am torn. What I have been doing lately is using Atom for frontend html/css/vanilla ES5. And vscode for anything I use the terminal with. I LOVE the integrated terminal with Git Bash. I am thinking about moving completely away from Atom

  • @uimonk
    @uimonk 5 років тому

    U did great

  • @pasqualecannavacciuolo61
    @pasqualecannavacciuolo61 5 років тому

    Clear and simple

  • @vinsentchitekwe6106
    @vinsentchitekwe6106 7 років тому +2

    Awesome!

  • @joe86569
    @joe86569 6 років тому

    brad you are awesome :)

  • @amitgogna2701
    @amitgogna2701 7 років тому

    Thanks brad ,pls make some videos on bootstrap dashboard with some charts and bars in them

  • @duke4279
    @duke4279 3 роки тому

    thank you sir this is awesome content :)

  • @jimdart8219
    @jimdart8219 6 років тому

    I love Brads Tutorials. But now that boostrap 4 is stable, what a pain trying to get even the HTML to work right. Even had VSCode give me errors on the tags for the link to Bootstrap saying they were special and had to be escaped. Could not get the H1 to center and the form-control-lg, well that was md at best. Oh well on to bigger and better. Thanks Brad your the best.

  • @swathivenkatesh465
    @swathivenkatesh465 2 роки тому

    Thank you!!

  • @adamklepacz6322
    @adamklepacz6322 7 років тому +1

    BOOTSTRAP 4 UPDATE:
    For those who are watching after August 2017:
    change bootstrap card-block class to card-body class

  • @spongebobspongebob24
    @spongebobspongebob24 7 років тому

    wow. Your new intro looks nice.

  • @zxcvxcvify
    @zxcvxcvify 6 років тому

    thank you broooo
    amazing video

  • @inponderland
    @inponderland 6 років тому +1

    Emmet is awesome.

  • @fcandann
    @fcandann 7 років тому

    Nice Tutorial

  • @tendies
    @tendies 7 років тому

    Thank you sir!

  • @thinsmoke7679
    @thinsmoke7679 3 роки тому

    How do you centralize the input pounds in the middle. Something has changed with bootstrap since you released this. The box covers the entire webpage

  • @faisalahammad
    @faisalahammad 6 років тому

    You're awesome man

  • @syedmuhammaddanish4325
    @syedmuhammaddanish4325 4 роки тому

    amazing man

  • @arunkaiser
    @arunkaiser 7 років тому

    Awesome bro

  • @siro8472
    @siro8472 7 років тому +1

    he makes these shortcuts eg .container and it makes automatically the class with what?? emet?? what is the name?

  • @MLievens
    @MLievens 5 років тому

    bg- primary bg-success- bg-danger and instead of card-block: card-header

  • @blakeyeboah393
    @blakeyeboah393 7 років тому

    Nice video!