Hypotenuse calculator practice program in JavaScript 📐【6 minutes】

Поделиться
HTML-код
  • Опубликовано: 31 дек 2024

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

  • @BroCodez
    @BroCodez  2 года назад +21

    let a;
    let b;
    let c;
    document.getElementById("submitButton").onclick = function(){
    a = document.getElementById("aTextBox").value;
    a = Number(a);
    b = document.getElementById("bTextBox").value;
    b = Number(b);
    c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
    document.getElementById("cLabel").innerHTML = "Side C: " + c;
    }



    Document
    Side A:

    Side B:

    submit

    • @hoangnhan6612
      @hoangnhan6612 2 года назад

      I think you should add something like:
      If atextbox or btextbox is none then the clabel will print "you should fill all textbox"

    • @joyceasante8292
      @joyceasante8292 Год назад

      let a;
      let b;
      let c;
      a = window.prompt("Enter size a");
      a = Number(a);
      b = window.prompt("Enter size b");
      b = Number(b);
      c = Math.pow(a,2) + Math.pow(b,2);
      c = Math.sqrt(c);
      ________________________
      OR
      let a;
      let b;
      let c;
      a = window.prompt("Enter side a");
      a = Number(a);
      b = window.prompt("Enter side b");
      b = Number(b);
      c = Math.sqrt(Math.pow(a,2) + Math.pow(b,2));
      console.log("Side C:", c);
      ________________________
      Advanced Version of the Programme

      Document

      Side A:
      Side B:
      submit

      *******************************
      let a;
      let b
      let c;
      /*
      a = window.prompt("Enter side A);
      a = Number(a);
      b = window.prompt("Enter side B);
      b = Number(b);
      c = Math.sqrt(Math.pow(a,2) + Math.pow(b,2));
      console.log("Side C:",c);
      */
      document.getElementById("submitButton").onclick = function(){

      a = document.getElementById("aTextBox").value;
      a = Number(a);

      b = document.getElementById("bTextBox").value;
      b = Number(b);
      c = Math.sqrt(Math.pow(a,2) + Math.pow(b,2));
      document.getElementById("cLabel").innerHTML = "Side C:"+ c;
      }

  • @stephanieezat-panah7750
    @stephanieezat-panah7750 2 года назад +8

    You explain things with such clarity, essentially "documenting" by narrating, as you go.
    This is super, thank you so much

  • @yooowazzam9782
    @yooowazzam9782 11 месяцев назад

    I absolutely love you. You're amazing!

  • @AdrianStefanik1
    @AdrianStefanik1 Год назад +1

    Hello Bro! Another day of my JavaScript adventure with your videos... another day of giving the likes after every video. It goes sometimes a little too quick, but I am still learning new stuff and all the code works for me too, so... I am going further to the next video.

  • @aljundiaz3936
    @aljundiaz3936 Год назад

    Thanks BroCode it helps me a lot as first year college

  • @AmericanDragon134
    @AmericanDragon134 2 года назад +3

    I must to like this . This is very interesting.

  • @MohyDev
    @MohyDev 2 года назад +3

    // For the RUclips algorithm!

  • @lirimbytyqi1
    @lirimbytyqi1 2 года назад +1

    Perfect video 🎉!

  • @hemasai1
    @hemasai1 Год назад

    let base = Math.pow(window.prompt("Enter length of the base:"),2);
    let height= Math.pow(window.prompt("Enter the height of the triangle"),2);
    alert("The Hypotenuse of the Triangle is "+ Math.sqrt(base + height));
    Just tried to put very less variables.

  • @lucabinder9829
    @lucabinder9829 2 года назад +1

    Bro got me learning

  • @малосольные-окурки
    @малосольные-окурки 8 месяцев назад

    perfect! thank you very much!

  • @tibebetech4867
    @tibebetech4867 Год назад

    Great Job!

  • @TheEvertonDias
    @TheEvertonDias Год назад

    Thanks, Bro!

  • @sebastianteaca7794
    @sebastianteaca7794 2 года назад

    There is also a Math.hypot() function available in javascript

    • @BroCodez
      @BroCodez  2 года назад +7

      yes but that would defeat the purpose of the exercise

  • @hoatranminh5216
    @hoatranminh5216 Год назад

    Thank you, Bro

  • @MrLoser-ks2xn
    @MrLoser-ks2xn Год назад

    Thanks!

  • @ZUNAEED_IMRAN
    @ZUNAEED_IMRAN Год назад

    Hy Bro Thank's

  • @skagmag
    @skagmag Год назад

    Nice

  • @murtezagorur3130
    @murtezagorur3130 Год назад

    // comment down below

  • @PalashMehta-69420irl
    @PalashMehta-69420irl 4 месяца назад

    could you show how to do this but using a html textbox pls. thnx

  • @jofeherg
    @jofeherg 2 года назад

    Algo ritn

  • @iakuraa
    @iakuraa 2 года назад +1

    very random comment

  • @Grudi28
    @Grudi28 2 года назад +1

    based mega chad

  • @ObsidianSamurai
    @ObsidianSamurai 2 года назад

    Algorithm

  • @roycechriston5389
    @roycechriston5389 2 года назад

    Thank you Bro Code Happy to join Bro Code fam

  • @irakliabashidze9937
    @irakliabashidze9937 2 года назад

    Uncaught TypeError: Cannot read properties of null (reading 'value')
    at document.getElementById.onclick (index.js:7:44)
    document.getElementById.onclick @ index.js:7
    this is the error i get when i try to calculate.
    i thought i did something wrong but i copied your code and i still have this error can someone help?

    • @kidkoreli
      @kidkoreli Год назад

      in my case it was because in "Send" I missed "" at the end, your error may be due to an oversight.

    • @ngash_101
      @ngash_101 Год назад

      Getting same issue anybody who has solved it?

    • @samarthminocha4104
      @samarthminocha4104 Год назад

      Same issue please help

    • @joanna00js
      @joanna00js Год назад +1

      Remove type="button" from HTML file.
      Just

    • @muthaharsultana6383
      @muthaharsultana6383 Год назад

      may be see whether u given id or type for the button tag