I want to use the values in the array userInfo as parameters in the getBMR function. How do I do that?
function userInput() {
var gender = document.querySelector('input[name="gender"]:checked').value;
var length = document.getElementById('length').value;
var weight = document.getElementById('weight').value;
var age = document.getElementById('age').value;
if (length || weight || age === (strValue)) {
length = parseInt(length);
weight = parseInt(weight);
age = parseInt(age);
var userInfo = [gender, length, weight, age];
return userInfo;
}
}
function getBMR(gender, length, weight, age) {
// ...
}
Been googling like crazy but I can't seem to find the solution. Using the console.log after the array declaration I can clearly see that the array stores the data. My problem is getting this data outside the function.
Here's my HTML:
<html>
<head>
</head>
<body>
<form action="">
<input type="radio" name="gender" id="gender" value="male" checked="checked">Man<br>
<input type="radio" name="gender" id="gender" value="female">Kvinna<br>
<label>Längd</label>
<input type="number" id="length"></input>
<label>Vikt</label>
<input type="number" id="weight"></input>
<label>Ålder</label>
<input type="number" id="age"></input>
<button onclick="userInput()">Hämta BMR</button>
</form>
<p id="dittBMR"></p>
</body>
</html>
Really appreciating all the help that I can get!
Thanks!