Wich century in Javascript.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Wich century in Javascript..

Hey there! so the excercise is: Create a function that returns the century depending on the year given as a parameter. Sample Input 1993 Sample Output 20 Hint You need to divide 1993 by 100: 1993/100 = 19.93, then round it to the nearest integer, which is 20 in this case. I made: function main() { var x = parseInt(readLine(), 10) //the output console.log(calcCent(x)); } //complete the function function calcCent(x){ console.log(Math.ceil(x/100));} Wich returns 18 Undefined.. And i am not sure where the undefined is coming from! Thanks in advance for any help i can get!

3rd Aug 2021, 2:11 PM
Gregory
Gregory - avatar
2 Answers
+ 4
If anyone wants to know why it prints 'undefined' because the function doesn't return a value at the end. With console.log() inside a function, you don't need the outside one. return Math.ceil(x/100)
4th Aug 2021, 3:31 AM
Simba
Simba - avatar
+ 3
After looking at it for a couple minutes more i realised my mistake! Sorry for taking time out of everyone their day! and thank you again incase you wanted to help!
3rd Aug 2021, 2:14 PM
Gregory
Gregory - avatar