+ 1

Trying to solve which century in java script

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. function main() { var f= parseInt(readLine(), 10) //the output calcCent(f); } //complete the function function calcCent(){ var cen1= Math.ceil( f/100) console.log(calcCent(f)); } it is saying f is not defined

19th May 2021, 4:24 PM
Simisola Osinowo
Simisola Osinowo - avatar
14 RĂ©ponses
+ 10
function main() { var year = parseInt(readLine(), 10) //the output console.log(calcCent(year)); function calcCent(){ var calculation = year / 100; return Math.ceil(calculation); } }
26th Sep 2021, 2:36 PM
Ruslan Berezhniy
Ruslan Berezhniy - avatar
+ 2
you forgot the put f between the parentheses in calcCent()
19th May 2021, 4:27 PM
Dino Wun (Use the search bar plz!)
Dino Wun (Use the search bar plz!) - avatar
+ 1
Hello. This is my solution. function main() { var year = parseInt(readLine(), 10) //the output console.log(calcCent(year)); } //complete the function function calcCent(x){ return Math.ceil(x / 100); }
15th Dec 2021, 5:54 PM
Mircea Teodor Cofa
Mircea Teodor Cofa - avatar
+ 1
function main() { var year = parseInt(readLine(), 10) //the output console.log(calcCent(year)); } //complete the function function calcCent(year){ return Math.ceil(year/100); } Yep, you need to put "year" for the function name, just like it's called in the output.
16th Dec 2021, 2:07 PM
Rapha
+ 1
function main() { var year = parseInt(readLine(), 10) //the output console.log(calcCent(year)); function calcCent(){ var calculation = year / 100; return Math.ceil(calculation); } } Good Luck
25th Jan 2022, 8:38 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
0
Thanks Dino Wun (Use the search bar plz!) Now it's given another error It highlighted the Math.ceil And said maximum call stack size exceeded
19th May 2021, 4:38 PM
Simisola Osinowo
Simisola Osinowo - avatar
0
Look at the calcCent definition at the bottom, Dino Wun pointed out that you didn't have parameter <f> between the parentheses. Furthermore, you're calling the function again from inside the function itself like this console.log( calcCent( f ) ); That's how you got the stack size warning. function calcCent( f ) { console.log( Math.ceil( f / 100 ) ); }
19th May 2021, 9:04 PM
Ipang
0
there is shorter way to do it, but this is how I did it function main() { var year = parseInt(readLine(), 10) //the output console.log(calcCent(year)); } //complete the function function calcCent(year){ var a = Math.ceil(year); var b = a / 100; var result = Math.ceil(b); return result }
5th Sep 2022, 11:57 PM
Andres Moran Cabello
Andres Moran Cabello - avatar
0
function main() { var year = parseInt(readLine(), 10) //the output console.log(calcCent(year)); function calcCent(){ var calculation = year / 100; return Math.ceil(calculation); } }
16th Nov 2022, 5:16 AM
Pooja Patel
Pooja Patel - avatar
0
you can put the calcCent function inside the the main function or outside it .. both will give the correct solution function main() { var year = parseInt(readLine(), 10); function calcCent(x){ return Math.ceil(x/100); } //the output console.log(calcCent(year)); } ---------------------------------------------- function main() { var year = parseInt(readLine(), 10) //the output console.log(calcCent(year)); } // complete the function function calcCent(x){ return Math.ceil(x/100); }
10th Jan 2023, 12:47 PM
Shevar Sansiro
Shevar Sansiro - avatar
0
function main() { var year = parseInt(readLine(), 10) //the output console.log(calcCent(year)); } //complete the function function calcCent(year){ var calculation = year /100; return Math.ceil(calculation); }
8th Jun 2024, 9:52 AM
Akash Thakur
Akash Thakur - avatar