0

I'm not sure how to take 2 inputs and return another value. Also is there any way for me to be able to tell where my code is going wrong? I'm still trying to understand all the nuances of how HTML and Javascript work together. I'm currently reading through Eloquent javascript but i'm always looking for suggested resources.

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Wilks</title>
        <script type="text/javascript" src="wilks.js"></script>
    </head>
    <body>
        <p>
            <label for="bodyWeight">Weight:</label> 
            <input id="bodyWeight" type="number" placeholder="Pounds">
            <label for="Big 3 Total">Big 3 Total:</label>
            <input id="liftTotal" type="number" placeholder="800" >
            <button onclick="wilksCalculator(bodyWeight, liftTotal)">Analyze</button>
        </p>
        <p>Wilks Coefficient: <span id="outputWilks"></span></p>
    </body>
</html>

// wilks.js

var a =-216.0475144;
var b =16.2606339;
var c =-0.002388645;
var d =-0.00113732;
var e =7.01863E-06;
var f =-1.291E-08;
var x = document.getElementById("bodyWeight").value;
var inputTotal = document.getElementById("liftTotal").vaule;
//var outputWilks;

function wilksCalculator(bodyWeight, liftTotal) {
    bodyWeight = x;
    return (liftTotal * (500/((a+b*x)+(c(Math.pow(x,2)))+(d+(Math.pow(x,3)))+(e+(Math.pow(x,4)))+(f(Math.pow(x,5))))));

}

var wilks = document.getElementById("outputWilks").innerHTML;
if (wilks) {
    wilks.onsubmit = function () {
        this.wilks.value = wilksCalculator(this.bodyWeight.value, 
        this.liftTotal.value);
        return false;
    };
}

wilksCalculator();
4
  • "is there any way for me to be able to tell where my code is going wrong?" Check the console for errors. Commented Feb 13, 2018 at 18:54
  • Syntax typo: vaule instead of value. Commented Feb 13, 2018 at 18:55
  • there is a typo on 2nd last line vaule instead of value and also paste the function wilksCalculator for further guidance Commented Feb 13, 2018 at 18:57
  • A string (the output of .innerHTML) does not have an onsubmit property. Commented Feb 13, 2018 at 18:59

2 Answers 2

1

Try this

<p>
   <label for="bodyWeight">Weight:</label>  
<input id="bodyWeight" type="number" placeholder="Pounds"**/>**
<label for="Big 3 Total">Big 3 Total:</label>
<input id="liftTotal" type="number" placeholder="800" **/>**
<button onclick="wilksCalculator(bodyWeight, liftTotal)">Analyze</button>
</p>
<p>Wilks Coefficient: <span id="outputWilks"></span></p>
Sign up to request clarification or add additional context in comments.

Comments

0

I would add event listeners, then get values and calculate.

Note some errors in your function c(.. would be a function call, assumed you wanted to multiply. Same with f., Check the formula.

Took the variables out of global scope and put in the function. Fixed some typos.

function wilksCalculator(bodyWeight, liftTotal) {
  var a = -216.0475144;
  var b = 16.2606339;
  var c = -0.002388645;
  var d = -0.00113732;
  var e = 7.01863E-06;
  var f = -1.291E-08;
  var x = bodyWeight;
  return (liftTotal * (500 / ((a + b * x) + (c * (Math.pow(x, 2))) + (d + (Math.pow(x, 3))) + (e + (Math.pow(x, 4))) + (f * (Math.pow(x, 5))))));

}

function wilksClick() {
  var wilks = document.getElementById("outputWilks");
  var bodyWeight = document.getElementById("bodyWeight").value;
  var liftTotal = document.getElementById("liftTotal").value;
  wilks.innerHTML = wilksCalculator(bodyWeight, liftTotal);
  return false;
}
var el = document.getElementById("calculate-wilks");
el.addEventListener("click", wilksClick, false);
<body>
  <p>
    <label for="bodyWeight">Weight:</label>
    <input id="bodyWeight" type="number" placeholder="Pounds">
    <label for="liftTotal">Big 3 Total:</label>
    <input id="liftTotal" type="number" placeholder="800">
    <button id="calculate-wilks">Analyze</button>
  </p>
  <p>Wilks Coefficient: <span id="outputWilks"></span></p>
</body>

1 Comment

Note I did nothing about validating the input (range, numeric etc), just used it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.