diff --git a/14_Day_Error_handling/14_day_starter/scripts/main.js b/14_Day_Error_handling/14_day_starter/scripts/main.js index c6045c8..61a9ccf 100644 --- a/14_Day_Error_handling/14_day_starter/scripts/main.js +++ b/14_Day_Error_handling/14_day_starter/scripts/main.js @@ -1,2 +1,31 @@ -console.log(countries) -alert('Open the console and check if the countries has been loaded') \ No newline at end of file +// console.log(countries) +// alert('Open the console and check if the countries has been loaded') + +// Exercise Level 1 +try { + let firstName = 'Gideon'; + let fullName = firstName + lastName; +} catch (error) { + console.log('This is the error:', error.name) + console.log('This is the message:', error.message) +} finally { + console.log('I am not really important') +} + +// Exercise Level 2 +function divide(a, b) { + if (b === 0) { + throw new Error("Division by zero is not allowed."); + } + return a / b; + } + + try { + const result = divide(10, 0); // Attempt to divide by zero + console.log("Result:", result); + } catch (error) { + console.error("An error occurred:", error.message); + } + +// +