Refactoring Practice Flashcards

1
Q
let color;
if (status === 'offline') {
	color = 'red';
}
else {
	color = 'green';
}
A

let color = status === ‘offline’ ? ‘red’ : ‘green’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

let day = 7

if (day === 1) {
	console.log('MONDAY');
}
else if (day === 2) {
	console.log('TUESDAY');
}
else if (day === 3) {
	console.log('WEDNESDAY');
}
else if (day === 4) {
	console.log('THURSDAY');
}
else if (day === 5) {
	console.log('FRIDAY');
}
else if (day === 6) {
	console.log('SATURDAY');
}
else if (day === 7) {
	console.log('SUNDAY');
}
else {
	console.log('INVALID DAY');
}
A

let day = 7

switch (day) {
	case 1:
		console.log('MONDAY');
		break;
	case 2:
		console.log('TUESDAY');
		break;
	case 3:
		console.log('WEDNESDAY');
		break;
	case 4:
		console.log('THURSDAY');
		break;
	case 5:
		console.log('FRIDAY');
		break;
	case 6:
		console.log('SATURDAY');
		break;
	case 7:
		console.log('SUNDAY');
		break;
	default:
		console.log('INVALID DAY');
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly