Java script 5 Assuming that you have three integer variables
(Java script)
5.) Assuming that you have three integer variables, x, y and z, write code that outputs the largest value they hold.
6.) Write a method that takes an int parameter x and returns a double containing the value that is one third of x.
Solution
Please find the required program along with its output. Please see the comments against each line to understand the step.
5)
x = 15 //initialize x with some value
y = 52 //initialize y with some value
z = 19 //initialize z with some value
if (x > y) { //if x is larger than y
if(x > z){ //if x is larger than z also, then x is larger, else z is larger
large = x;
}else{
large = z;
}
} else { // else, y is larger than x
if(y > z){ //if y is larger than z also, then y is larger, else z is larger
large = y;
}else{
large = z;
}
}
console.log(\"Larger =\", large) //print the larger value among x, y and z in console
------------------------------------------------------
OUTPUT:
6)
function oneThird(x) { //function that return one third of x
return (x/3); //return 1/3 of x => x/3
}
console.log(\"One third of 8 = \",oneThird(8)) //print the oneThird of a number in console
-------------------------------------
OUTPUT:
