JSFiddle - React, Tailwind, and code Playground

by tjnicolaides

JavaScript

var myTasks = [{
    'name': 'Laundry'
}, {
    'complete': true
}, {
    'name' : 'Homework',
    'complete' : false
}];

for(var i = 0; i < myTasks.length; i++) {
    try {
       print(myTasks[i]);
    } catch (error) {
        console.log(error);
    }
}

function print(theTask) {
    if(typeof theTask.name == 'undefined') {
        throw 'The task name is missing!'
    } else if (typeof theTask.complete == 'undefined') {
        throw 'The task status is missing!'
    } else {
        console.log('print this out as a fancy list item with a check next to it if theTask.complete is true.');
    }
}