In: Computer Science
For this question you will need to use the following library function: Math.floor(x) returns the largest whole number less than or equal to x Define a function named weight which has one input. The input is a Number representing a person's weight in pounds. Your function will calculate and return a string saying how much they weigh in stone. Your function should start by multiplying the input by 0.0714286. Because stone weight is always a whole number, your function will need to use the Math.floor to get the whole number portion of that product. The function needs to return a String with the text You weigh ______ stone (replacing the underscores with the weight in stone your function calculated). in Java script please.
Pounds to Stone Weight Conversion
Code:
<!DOCTYPE html>
<html>
<title>Weight Converter</title>
<body style="text-align: center;">
<h2 style="margin-top: 200px;">
Weight Converter
</h2>
<p>
Please enter an input value in pounds
</p>
<p>
<label>
Input value
</label>
<input id="ipPounds" type="number" placeholder="Pounds" oninput="Weight(this.value)" onchange="Weight(this.value)">
</p>
<p>
You weigh <span id="opStones"></span> stones
</p>
<script>
function Weight(valNum) {
document.getElementById("opStones").innerHTML = Math.floor(valNum*0.0714286);
}
</script>
</body>
</html>
Output: