27.2 Average of Three Javascript | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

27.2 Average of Three Javascript

Can anyone tell me what's wrong with this code: function main() { var num1 = parseInt(readLine(),10); var num2 = parseInt(readLine(),10); var num3 = parseInt(readLine(),10); var average; //assign the average value to the variable average console.log(average) } //complete the function function avg(num1,num2,num3){ var average = (num1 + num2 +num3) / 3; return average; }

27th Jan 2022, 12:36 PM
Bball4Life
3 ответов
+ 5
Calling the function avg with 3 numbers passing will give back or return a value with calculating average, which should be assigned to average variable. You don't have any value assigned to variable. And function is unused still. So do above steps.. If you Don't know: complete functions lesson.. Hope it helps..
27th Jan 2022, 12:52 PM
Jayakrishna 🇮🇳
+ 2
function main() { var num1 = parseInt(readLine(),10); var num2 = parseInt(readLine(),10); var num3 = parseInt(readLine(),10); var average = avg(num1 ,num2 ,num3 ); //assigns the average value to the variable average, which is calculated and returned from function avg. console.log(average); } //complete the function function avg(num1,num2,num3){ var average = (num1 + num2 +num3) / 3; return average; } //this is code what is asked to write. Use of function and getting a return value
29th Jan 2022, 9:41 AM
Jayakrishna 🇮🇳
+ 1
I improvised and got the right result, but I would still like to know what the clean code for this challenge looks like. //complete the function function avg(){ var num1 = parseInt(readLine(),10); var num2 = parseInt(readLine(),10); var num3 = parseInt(readLine(),10); console.log ((num1 + num2 +num3) / 3); } avg();
28th Jan 2022, 12:50 PM
Bball4Life