The 'undefined' error; how to stop it?



I generally have been having this problem everywhere, even in simple scripts like this one:

function doCatsEnjoyEatingCheez() {

var pusheenStatus = true;

var normalCats = false;

var bananyaStatus = false;

var catFood = 'Fish satchets';

if (pusheenStatus === true) {
console.log('Pusheen likes to eat cheeze, however...');

} else if (pusheenStatus === false) {
console.log('Pusheen doesn\'t want anything to do with cheeze');

} if (normalCats === false) {

} else if (normalCats === true) {
console.log('Cheez is a favourite of a regular cat');

} if (bananyaStatus === true) {
console.log('In the series, the Bananyas are seen eating cheez in the fridge');

} else if (bananyaStatus === false){
console.log('Bananya only likes sweet treats');

} else {
console.log('Please select a valid option');


I don’t really get what I’m doing wrong here. Thanks


It’s spaghetti code.
You need to revisit how if-else statements work
There are better ways to do what you attempted with mastery of control flow


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.