error-handling.js

Run Settings
LanguageJavaScript
Language Version
Run Command
// kode kuis dicoding error handling // TODO 1 class ValidationError extends Error { // todo 1 constructor (message) { super(message); this.name = "ValidationError"; } } // TODO 2 const validateNumberInput =(a,b,c)=>{ if(typeof(a)!=='number'){ throw new ValidationError("Argumen pertama harus number"); } if(typeof(b)!=='number'){ throw new ValidationError("Argumen kedua harus number"); } if(typeof(c)!=='number') { throw new ValidationError("Argumen ketiga harus number"); } } const detectTriangle = (a, b, c) => { // TODO 3 try { validateNumberInput(a,b,c); if (a === b && b === c) { return 'Segitiga sama sisi'; } if (a === b || a === c || b === c) { return 'Segitiga sama kaki'; } return 'Segitiga sembarang'; } catch (error){ return error.message; } }; console.log(detectTriangle(1,2,3));
Editor Settings
Theme
Key bindings
Full width
Lines