const getMessages = (status) => { // if(status === 'received'){ // return 'We are working on your order' // }else if(status === 'prepared'){ // return `Food is ready for collection` // }else if(status === 'onroute'){ // return `Your food is on its way` // }else if(status === 'arrived'){ // return `Your food has been delivered and signed for` // }else{ // return `unknown status` // } const messages = { received: 'We are working on your order', prepared: `Food is ready for collection`, onroute: `Your food is on its way`, arrived: `Your food has been delivered and signed for` } return messages[status] ?? 'unknown status' } const user = { name: 'David', status: 'arrived' } console.log(getMessages(user.status))
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter