From ac4dc6c655583f6f14d91632c92f314a91291645 Mon Sep 17 00:00:00 2001 From: vboxuser Date: Sat, 11 Nov 2023 15:12:50 +0000 Subject: [PATCH] errors, exercises and explore done --- week-1/errors/1.js | 3 ++- week-1/errors/3.js | 5 ++++- week-1/errors/4.js | 5 +++-- week-1/exercises/count.js | 2 ++ week-1/exercises/decimal.js | 10 +++++++--- week-1/exercises/initials.js | 2 ++ week-1/exercises/paths.js | 4 ++++ week-1/exercises/random.js | 4 ++++ week-1/explore/chrome.md | 3 +++ 9 files changed, 31 insertions(+), 7 deletions(-) diff --git a/week-1/errors/1.js b/week-1/errors/1.js index 7a43cbea..2dc1d4d6 100644 --- a/week-1/errors/1.js +++ b/week-1/errors/1.js @@ -1,4 +1,5 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +var age = 33; age = age + 1; +console.log(age); \ No newline at end of file diff --git a/week-1/errors/3.js b/week-1/errors/3.js index ffa72ca4..5516239b 100644 --- a/week-1/errors/3.js +++ b/week-1/errors/3.js @@ -1,7 +1,10 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +let stringNumber = cardNumber.toString(); +const last4Digits =stringNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working // Make and explain a prediction about why the code won't work + // // Then try updating the expression last4Digits is assigned to, in order to get the correct value +console.log(last4Digits); \ No newline at end of file diff --git a/week-1/errors/4.js b/week-1/errors/4.js index 21dad8c5..d6d3ccb1 100644 --- a/week-1/errors/4.js +++ b/week-1/errors/4.js @@ -1,2 +1,3 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const HourClockTime12 = "20:53"; +const hourClockTime24 = "08:53"; + //variable can not start with numer symbol \ No newline at end of file diff --git a/week-1/exercises/count.js b/week-1/exercises/count.js index 117bcb2b..b9ff8770 100644 --- a/week-1/exercises/count.js +++ b/week-1/exercises/count.js @@ -4,3 +4,5 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing + //in line 3 the variable count is increase by one. + console.log(count) diff --git a/week-1/exercises/decimal.js b/week-1/exercises/decimal.js index bd4a4740..e3b54f4f 100644 --- a/week-1/exercises/decimal.js +++ b/week-1/exercises/decimal.js @@ -1,10 +1,14 @@ const num = 56.5467; -// You should look up Math functions for this exercise https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math - +// You should look up Math functions for this exercise // Create a variable called wholeNumberPart and assign to it an expression that evaluates to 56 ( the whole number part of num ) + var wholeNumberpart= Math.floor(num); // Create a variable called decimalPart and assign to it an expression that evaluates to 0.5467 ( the decimal part of num ) + var decimalpart= num-Math.floor(num); // Create a variable called roundedNum and assign to it an expression that evaluates to 57 ( num rounded to the nearest whole number ) - + var rounded= Math.round(num); // Log your variables to the console to check your answers +console.log(wholeNumberpart); +console.log(decimalpart); + console.log(rounded); \ No newline at end of file diff --git a/week-1/exercises/initials.js b/week-1/exercises/initials.js index 50b62103..84b05da0 100644 --- a/week-1/exercises/initials.js +++ b/week-1/exercises/initials.js @@ -4,3 +4,5 @@ let lastName = "Johnson"; // Declare a variable called initials that stores the first character of each string in upper case to form the user's initials // Log the variable in each case +var initials= `${firstName.charAt(0).toUpperCase()} ${middleName.charAt(0).toUpperCase()}${lastName.charAt(0).toUpperCase()}`; +console.log(initials) \ No newline at end of file diff --git a/week-1/exercises/paths.js b/week-1/exercises/paths.js index c91cd2ab..4af6dc9b 100644 --- a/week-1/exercises/paths.js +++ b/week-1/exercises/paths.js @@ -15,4 +15,8 @@ const base = filePath.slice(lastSlashIndex + 1); console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable +const dirpath= filePath.slice(0,-8); +console.log(dirpath); +console.log(base); // Create a variable to store the ext part of the variable + diff --git a/week-1/exercises/random.js b/week-1/exercises/random.js index 79a4a4d5..11762e26 100644 --- a/week-1/exercises/random.js +++ b/week-1/exercises/random.js @@ -4,6 +4,10 @@ const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // In this exercise, you will need to work out what num represents? + // Try breaking down the expression and using documentation to explain what it means + // the num variable first find random number 1 up to 100 then round the number + // and multiplay by maximum -minimum and add one finally add minimum // It will help to think about the order in which expressions are evaluated // Try logging the value of num several times to build an idea of what the program is doing + console.log(num); \ No newline at end of file diff --git a/week-1/explore/chrome.md b/week-1/explore/chrome.md index e7dd5fea..5fec4553 100644 --- a/week-1/explore/chrome.md +++ b/week-1/explore/chrome.md @@ -11,8 +11,11 @@ In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? +alert is small box at the top that display a text Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. What effect does calling the `prompt` function have? +prompt is a dialog box that the propmts user for input What is the return value of `prompt`? +ok or cancel