+ 1
Why does the the first way work but not the second?
function main() { var num1 = parseInt(readLine(),10); var num2 = parseInt(readLine(),10); var num3 = parseInt(readLine(),10); var average = (avg(num1,num2,num3 ) / 3) console.log(average) function avg(n1,n2,n3){ return n1 + n2 + n3 } Vs function main() { var num1 = parseInt(readLine(),10); var num2 = parseInt(readLine(),10); var num3 = parseInt(readLine(),10); var average = (avg(num1,num2,num3 )) console.log(average) } function avg(n1,n2,n3){ return n1 + n2 + n3 / 3 }
2 ответов
+ 2
In 2nd way, you have to use return (n1+n2+n3)/3
0
2nd doesn't works because:
n1+n2+n3/3 == n1+n2+(n3/3) != (n1+n2+n3)/3