Medium
You're building a notification system for a social media platform. Users can receive notifications in different languages based on their preferences. Given the notification handler below, what will be logged to the console when processing notifications for a Spanish-speaking user?
1class NotificationHandler {2 constructor(userLanguage) {3 this.language = userLanguage;4 this.templates = {5 en: {6 welcome: (name) => `Welcome back, ${name}!`,7 newMessage: (count) => `You have ${count} new messages`8 },9 es: {10 welcome: (name) => `¡Bienvenido nuevamente, ${name}!`,11 newMessage: (count) => `Tienes ${count} mensajes nuevos`12 }13 };14 }1516 async processNotifications(userName, messageCount) {17 const notifications = [];18 try {19 const welcomeMsg = this.templates?.[this.language]?.welcome(userName);20 notifications.push(welcomeMsg);2122 if (messageCount > 0) {23 const msgNotification = this.templates[this.language].newMessage(messageCount);24 notifications.push(msgNotification);25 }2627 return Promise.all(notifications);28 } catch (error) {29 return ['Notification error occurred'];30 }31 }32}3334const handler = new NotificationHandler('es');35handler.processNotifications('Carlos', 3)36 .then(console.log);