const expr = 'Papayas';
switch (expr) {
case 'Oranges':
console.log('Oranges are $0.59 a pound.');
break;
case 'Mangoes':
case 'Papayas':
console.log('Mangoes and papayas are $2.79 a pound.');
// expected output: "Mangoes and papayas are $2.79 a pound."
break;
default:
console.log(`Sorry, we are out of ${expr}.`);
}
const expr = 'Papayas';
switch (expr) {
case 'Oranges': {
const result = expr + 'org';
console.log('Oranges are $0.59 a pound.');
break;
}
case 'Papayas': {
const result = expr + 'org';
console.log('Mangoes and papayas are $2.79 a pound.');
// expected output: "Mangoes and papayas are $2.79 a pound."
break;
}
default: {
const result = expr + 'org';
console.log(`Sorry, we are out of ${result}.`);
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.