I was just trying to exercise some new stuff im learning, but the code below won’t print anything to the console and i’m not sure why
const newApartment = 1600
let wallet = 1000
function apartmentMove() {
if (wallet >= newApartment){
console.log(‘Approved!’)
return console.log(‘Denied!’);
}
};
any guidance would be greatly appreciated. I know it’s sup[er simple, but something isn’t registering yet and idk what.
Move the “Return” statement to after the very end of the function, after the final console.log. What you have here is returning from the function before the second console log runs.
2 Likes
Hongz
January 31, 2025, 5:25pm
3
The way you wrote function is wrong. Here is my suggestion you can try
const newApartment = 1600;
let wallet = 1000;
const status = apartmentMove(wallet);
console.log('Apartment move has been ' + status);
function apartmentMove(w = 0) {
return w >= newApartment ? 'Approved' : 'Denied';
}
You can refactor function with arrow function as well
const apartmentMove = (w = 0) => w >= newApartment ? 'Approved' : 'Denied';
1 Like