From a5f6c86d620646ede4af8111df36b558710d324e Mon Sep 17 00:00:00 2001 From: Jim Cramer Date: Thu, 28 Nov 2024 12:22:13 +0100 Subject: [PATCH 1/2] First exercise --- .../Week2/assignment/ex1-giveCompliment.js | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/1-JavaScript/Week2/assignment/ex1-giveCompliment.js b/1-JavaScript/Week2/assignment/ex1-giveCompliment.js index 93806cfaf..b0a23639c 100644 --- a/1-JavaScript/Week2/assignment/ex1-giveCompliment.js +++ b/1-JavaScript/Week2/assignment/ex1-giveCompliment.js @@ -17,20 +17,40 @@ Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-J Use `console.log` each time to display the return value of the `giveCompliment` function to the console. -----------------------------------------------------------------------------*/ -export function giveCompliment(/* TODO parameter(s) go here */) { - // TODO complete this function +export function giveCompliment(name) { + //Array of compliments names + const compliments = [ + 'amazing', + 'awesome', + 'brilliant', + 'clever', + 'wonderful', + 'excelent', + 'fantastic', + 'funny', + 'smart', + ]; + // Randomly select a compliment + const randomIndex = Math.floor(Math.random() * compliments.length); + const compliment = compliments[randomIndex]; + + // Return the compliment string + return `You are ${compliment}, ${name}!`; } function main() { - // TODO substitute your own name for "HackYourFuture" - const myName = 'HackYourFuture'; + const myName = 'Hossein'; + // Call the function three times with myName console.log(giveCompliment(myName)); console.log(giveCompliment(myName)); console.log(giveCompliment(myName)); - const yourName = 'Amsterdam'; + // Another example with a different name + const yourName = 'Kelisa'; + +// Call the function three times with yourName console.log(giveCompliment(yourName)); console.log(giveCompliment(yourName)); console.log(giveCompliment(yourName)); @@ -39,4 +59,4 @@ function main() { // ! Do not change or remove the code below if (process.env.NODE_ENV !== 'test') { main(); -} +} \ No newline at end of file From 44fdfef3e6a0fe495526445d8bce5bd934fac05b Mon Sep 17 00:00:00 2001 From: Jim Cramer Date: Thu, 28 Nov 2024 12:23:51 +0100 Subject: [PATCH 2/2] Update --- .../Week2/assignment/ex1-giveCompliment.js | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/1-JavaScript/Week2/assignment/ex1-giveCompliment.js b/1-JavaScript/Week2/assignment/ex1-giveCompliment.js index b0a23639c..a8697cfbf 100644 --- a/1-JavaScript/Week2/assignment/ex1-giveCompliment.js +++ b/1-JavaScript/Week2/assignment/ex1-giveCompliment.js @@ -19,20 +19,20 @@ Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-J -----------------------------------------------------------------------------*/ export function giveCompliment(name) { //Array of compliments names - const compliments = [ - 'amazing', - 'awesome', - 'brilliant', - 'clever', - 'wonderful', - 'excelent', - 'fantastic', - 'funny', - 'smart', - ]; + const compliments = [ + 'amazing', + 'awesome', + 'brilliant', + 'clever', + 'wonderful', + 'excellent', + 'fantastic', + 'funny', + 'smart', + ]; // Randomly select a compliment const randomIndex = Math.floor(Math.random() * compliments.length); - const compliment = compliments[randomIndex]; + const compliment = compliments[randomIndex]; // Return the compliment string return `You are ${compliment}, ${name}!`; @@ -41,16 +41,15 @@ export function giveCompliment(name) { function main() { const myName = 'Hossein'; - // Call the function three times with myName + // Call the function three times with myName console.log(giveCompliment(myName)); console.log(giveCompliment(myName)); console.log(giveCompliment(myName)); - // Another example with a different name const yourName = 'Kelisa'; -// Call the function three times with yourName + // Call the function three times with yourName console.log(giveCompliment(yourName)); console.log(giveCompliment(yourName)); console.log(giveCompliment(yourName)); @@ -59,4 +58,4 @@ function main() { // ! Do not change or remove the code below if (process.env.NODE_ENV !== 'test') { main(); -} \ No newline at end of file +}