🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.

Project 25: Chat App Interface

JS Wizard
Step 1 of 3
Project

try / catch

Wrap JSON.parse on a possibly-malformed incoming message in a try/catch block, logging a friendly error instead of letting the whole script crash. try/catch lets you handle an operation that might throw without stopping every other part of the app.

🎯 Your Task

Please add the exact code shown in the light gray box below to your editor.Do not delete your previous code, just insert these new lines in the correct place!

const incomingMessage = "{ not valid json";

try {
  const parsed = JSON.parse(incomingMessage);
  console.log(parsed);
} catch (err) {
  console.log("Couldn't parse incoming message:", err.message);
}