In: Computer Science
java script
Define a function named height which has two inputs. This first input is the number of feet. The second input is the number of inches. Both inputs will be Number values. Your function must calculate and return a Number. he returned value represents number of meters equal to the input. Your function should start by multiplying the first parameter by 0.3048 (1 foot is 0.3048 meters). Then multiply the second input by 0.0254 (1 inch is 0.0254 meters). Your function must return the sum of those two products. Sample test cases: height(0.0, 100.0) would evaluate to 2.54 (finds bug in how second parameter converted) height(100.0, 0.0) would evaluate to 30.48 (finds bug in how first parameter converted) height(100.0, 100.0) would evaluate to 33.02 (finds bug if not adding result of converting both parameters)
A2For 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). Sample test cases: weight(196.0) would evaluate to "You weigh 14 stone" (finds bug in calculation since rounding not needed) weight(153.5) would evaluate to "You weigh 10 stone" (finds bug in rounding step)
Answer 1)
Sample output:
Program screenshot:
Program code to copy:
// function returns height in metres
function height(feet, inches) {
return (0.3048 * feet) + (0.0254 * inches);
}
// test inputs
console.log(height(0.0, 100.0))
console.log(height(100.0, 0.0))
console.log(height(100.0, 100.0))
----------------------------------------------------------------------------------------
Answer 2)
Sample output:
Program screenshot:
Program code to copy:
// function returns weight in stone
function weight(inputWeight) {
var outputWeight = Math.floor(inputWeight *
0.0714286);
return "You weigh " + outputWeight + "
stone";
}
// Test input
console.log(weight(196.0))
console.log(weight(153.5))