The 'undefined' error; how to stop it?


#1

Hello!

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) {
console.log(catFood);

} 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


#2

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


#3

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