+ 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
11 ответов
+ 10
function main() {
var year = parseInt(readLine(), 10)
//the output
console.log(calcCent(year));
function calcCent(){
var calculation = year / 100;
return Math.ceil(calculation);
}
}
+ 2
you forgot the put f between the parentheses in calcCent()
+ 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);
}
+ 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.
+ 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
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
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 ) );
}
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
}
0
function main() {
var year = parseInt(readLine(), 10)
//the output
console.log(calcCent(year));
function calcCent(){
var calculation = year / 100;
return Math.ceil(calculation);
}
}
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);
}
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);
}