From 115fc504a923e57c8a7c633cdeeaf36234070ab9 Mon Sep 17 00:00:00 2001 From: Gideon-Buba Date: Tue, 5 Sep 2023 20:33:32 +0100 Subject: [PATCH] Completed day 14 --- .../14_day_starter/scripts/main.js | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) 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); + } + +// +