简体   繁体   中英

I am trying to create a function based on user input. What am I doing with my Code?

My goal is to get user input for different variables and then use the input to create an equation. The equation should read like this U1= 2*((DM/2)(D2)) ; U2= D1/ (DS/2); U3= (U1-U2) ; U4 = (D2-D1); U= (U3/U4).

Do I have to do document.getelementbyId tag or is there an another way.

       <html>
       <head>

       <script>
        var DM
        DM = prompt ("Moon's Diameter");
        var DE
        DE = prompt ("Earth's Diameter");
           var DS
        DS = prompt ("Sun's Diameter");
        var D1
         D1 = prompt ("Distance from Earth to the Moon");
        var D2
         D2= prompt ("Distance from Sun to the Moon");

       function umbra() {
       var U1 = (2*((DM/2) * (D2));
      return (U1);
      var U2 = (D1)*(DS/2);
          return (U2);
      var U3= U1-U2;
        return (U3);
       var U4 = (D2-D1);
     return (U4)
    var U = (U3/U4)
    return (U)
     }
    document.write(umbra)
    </script>
    </head>
    <body>

    </body>
    </html>

Creat a little Web page, Use HTML input fields, let the user type their numbers, create a "Calculate" button, and display the result on click in a read-only input field.

Consider using jQuery. It makes things easier.

There's a bizillion calculators on the net that work like this. Google "volume calc" "mortgage calc" "auto calc" etc for examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM