Cannot understand what is going wrong even tried testing out the logic by logging into the console. Everything looks allright there but still cannot pass all the checkpoints.
Your code so far
function isLeapYear(num) {
if (year % 4 == 0 && year % 100 !== 0 ||year % 400 == 0) {
return year + " is a leap year."
} else {
return `${year} is not a leap year.`
};
}
let year = 1900;
const result = isLeapYear(year);
console.log(result);
year = 2000;
console.log(isLeapYear(year));
year = 2024;
console.log(isLeapYear(year))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0
Challenge Information:
Build a Leap Year Calculator - Build a Leap Year Calculator
You have a parameter num in your function definition, but you are not using it inside your function. You shouldn’t be explicitly working with a global variable (year) inside your function.
thanks for the help that was really silly of me also can you please explain why we shouldn’t explicitly work with global variables inside of a function.
A function could become problematic if it were hard-coded with global variables as, for instance, it could return errors or erroneous values if taken out of the context of the global variable (or if the global variable went AWOL or had its value changed unexpectedly etc).
A function is much more flexible (and universally applicable) if it works only with the parameters with which it is defined. This means that you are always in control of the input and output values of the function.
There’s no reason why you can’t pass a global variable as an argument to a function parameter though…