Hey there, I'm struggling with converting my function/array to JSON format. Can anyone lend a hand?
I attempted using JSON.stringify(obj) but couldn't quite get it to work. It's all a bit confusing for me at the moment.
I would be really grateful for any assistance offered.
Thanks in advance!
var answer1 = "No"
var mood1 = "I'm tired";
var answer2 = "No today"
var mood2 = "Not cool at all";
var answer3 = "maybe"
var mood3 = "just tired";
var answer4 = "yes";
var mood4 = "i'm ready for it";
console.log(LearnObject(answer1, mood1));
function LearnObject(reason, mood) {
var obj = [];
var notValidAnswer = 'Try again';
var shortReason = ' Please explain your feelings in more details';
switch (answer) {
case 'yes':
obj.push('Nice');
break;
case 'no':
obj.push('not at all');
break;
case 'maybe':
obj.push('be nicer');
break;
default:
obj.push(notValidAnswer);
}
if (validate(reason) && obj.indexOf(notValidAnswer) == -1) {
obj.push(shortReason);
}
var objLength = obj.length;
for (var i = 0; i < objLength; i++) {
obj.push("Enjoy your day");
}
return obj;
}
function validate(reason) {
return reason.split('').length < 3
}