Is there a way to refactor this code in order to prevent repeating dailogObj.image
? I would have used a return
statement if it wasn't for case 5 where two assignments are required.
getDialogData(imageNum): any {
const dailogObj = {
image: '',
buttonName: 'Learn More'
};
switch (imageNum) {
case 1:
dailogObj.image = '../../../assets/images/Red-Image.png';
break;
case 2:
dailogObj.image = '../../../assets/images/blue-image-orgl.png';
break;
case 3:
dailogObj.image = '../../../assets/images/Green-Image-2.png';
break;
case 4:
dailogObj.image = '../../../assets/images/Gold-Image.png';
break;
case 5:
dailogObj.image = '../../../assets/images/green-img-orgl.png';
dailogObj.buttonName = 'Read Her Story';
break;
case 6:
dailogObj.image = '../../../assets/images/Red-Image-2.png';
break;
case 7:
dailogObj.image = '../../../assets/images/Blue-Image-2.png';
break;
case 8:
dailogObj.image = '../../../assets/images/Gold-Image-2.png';
break;
}
return dailogObj;
}