-
Notifications
You must be signed in to change notification settings - Fork 7
Hadid w2 javascript #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
dce57a7
85288a5
84f2263
2223d93
1688ff7
90daffc
8b16f37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| ## Test Summary | ||
|
|
||
| **Mentors**: For more information on how to review homework assignments, please refer to the [Review Guide](https://github.com/HackYourFuture/mentors/blob/main/assignment-support/review-guide.md). | ||
|
|
||
| ### 1-JavaScript - Week2 | ||
|
|
||
| | Exercise | Passed | Failed | ESLint | | ||
| |----------------------|--------|--------|--------| | ||
| | ex1-giveCompliment | 7 | - | ✓ | | ||
| | ex2-dogYears | 7 | - | ✓ | | ||
| | ex3-tellFortune | 10 | - | ✓ | | ||
| | ex4-shoppingCart | - | - | ✓ | | ||
| | ex5-shoppingCartPure | - | - | ✓ | | ||
| | ex6-totalCost | - | - | ✓ | | ||
| | ex7-mindPrivacy | - | - | ✓ | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,33 @@ | ||
| /* ----------------------------------------------------------------------------- | ||
| Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-JavaScript/Week3#exercise-1-you-are-amazing | ||
|
|
||
| 1. Complete the function named `giveCompliment`as follows: | ||
|
|
||
| - It should take a single parameter: `name`. | ||
| - Its function body should include a variable that holds an array, | ||
| `compliments`, initialized with 10 strings. Each string should be a | ||
| compliment, like `"great"`, `"awesome"` and so on. | ||
| - It should randomly select a compliment from the array. | ||
| - It should return the string "You are `compliment`, `name`!", where | ||
| `compliment` is a randomly selected compliment and `name` is the name that | ||
| was passed as an argument to the function. | ||
|
|
||
| 2. Call the function three times, giving each function call the same argument: | ||
| your name. | ||
| 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) { | ||
| const compliments = [ | ||
| "great", | ||
| "awesome", | ||
| "fantastic", | ||
| "brilliant", | ||
| "wonderful", | ||
| "amazing", | ||
| "incredible", | ||
| "outstanding", | ||
| "marvelous", | ||
| "exceptional" | ||
| ]; | ||
|
|
||
| const i = Math.floor(Math.random() * compliments.length); | ||
| return `You are ${compliments[i]}, ${name}!`; | ||
| } | ||
|
|
||
| function main() { | ||
| // TODO substitute your own name for "HackYourFuture" | ||
| const myName = 'HackYourFuture'; | ||
|
|
||
| const myName = "Rim"; | ||
| console.log(giveCompliment(myName)); | ||
| console.log(giveCompliment(myName)); | ||
| console.log(giveCompliment(myName)); | ||
|
|
||
| const yourName = 'Amsterdam'; | ||
|
|
||
| const yourName = "Hadid"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| console.log(giveCompliment(yourName)); | ||
| console.log(giveCompliment(yourName)); | ||
| console.log(giveCompliment(yourName)); | ||
| } | ||
|
|
||
| // ! Do not change or remove the code below | ||
| if (process.env.NODE_ENV !== 'test') { | ||
| if (process.env.NODE_ENV !== "test") { | ||
| main(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| export const compliments = [ | ||
| "great", | ||
| "awesome", | ||
| "fantastic", | ||
| "brilliant", | ||
| "wonderful", | ||
| "amazing", | ||
| "incredible", | ||
| "outstanding", | ||
| "marvelous", | ||
| "exceptional" | ||
| ]; | ||
|
|
||
| export function giveCompliment(name) { | ||
| const i = Math.floor(Math.random() * compliments.length); | ||
| return `You are ${compliments[i]}, ${name}!`; | ||
| } | ||
|
|
||
| function main() { | ||
| const myName = "HackYourFuture"; | ||
| console.log(giveCompliment(myName)); | ||
| console.log(giveCompliment(myName)); | ||
| console.log(giveCompliment(myName)); | ||
|
|
||
| const yourName = "Amsterdam"; | ||
| console.log(giveCompliment(yourName)); | ||
| console.log(giveCompliment(yourName)); | ||
| console.log(giveCompliment(yourName)); | ||
| } | ||
|
|
||
| if (process.env.NODE_ENV !== "test") { | ||
| main(); | ||
| } | ||
| 1. Complete the function named `giveCompliment`as follows: | ||
|
|
||
| export function giveCompliment(name) { | ||
| const compliments = [ | ||
| "great", | ||
| "awesome", | ||
| "fantastic", | ||
| "brilliant", | ||
| "wonderful", | ||
| "amazing", | ||
| "incredible", | ||
| "outstanding", | ||
| "marvelous", | ||
| "exceptional" | ||
| ]; | ||
| const i = Math.floor(Math.random() * compliments.length); | ||
| return `You are ${compliments[i]}, ${name}!`; | ||
| } | ||
|
|
||
| function main() { | ||
| const myName = "HackYourFuture"; | ||
| console.log(giveCompliment(myName)); | ||
| console.log(giveCompliment(myName)); | ||
| console.log(giveCompliment(myName)); | ||
|
|
||
| const yourName = "Amsterdam"; | ||
| console.log(giveCompliment(yourName)); | ||
| console.log(giveCompliment(yourName)); | ||
| console.log(giveCompliment(yourName)); | ||
| } | ||
|
|
||
| if (process.env.NODE_ENV !== "test") { | ||
| main(); | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,14 @@ | ||
| /*------------------------------------------------------------------------------ | ||
| Full description at: https://github.com/HackYourFuture/Assignment/tree/main/1-JavaScript/Week3#exercise-2-dog-years | ||
|
|
||
| You know how old your dog is in human years, but what about dog years? Let's | ||
| calculate it! | ||
|
|
||
| 1. Complete the function named `calculateDogAge`. | ||
|
|
||
| - It takes one parameter: your (fictional) puppy's age (number). | ||
| - Calculate your dog's age based on the conversion rate of 1 human year to | ||
| 7 dog years. | ||
| - Return a string: "Your doggie is `age` years old in dog years!" | ||
|
|
||
| 2. Use `console.log` to display the result of the function for three different | ||
| ages. | ||
| -----------------------------------------------------------------------------*/ | ||
|
|
||
| export function calculateDogAge(/* TODO parameter(s) go here */) { | ||
| // TODO complete this function | ||
| export function calculateDogAge(humanYears) { | ||
| const dogYears = humanYears * 7; | ||
| return `Your doggie is ${dogYears} years old in dog years!`; | ||
|
Comment on lines
+2
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| } | ||
|
|
||
| function main() { | ||
| console.log(calculateDogAge(1)); // -> "Your doggie is 7 years old in dog years!" | ||
| console.log(calculateDogAge(2)); // -> "Your doggie is 14 years old in dog years!" | ||
| console.log(calculateDogAge(3)); // -> "Your doggie is 21 years old in dog years!" | ||
| console.log(calculateDogAge(1)); | ||
| console.log(calculateDogAge(2)); | ||
| console.log(calculateDogAge(3)); | ||
|
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| } | ||
|
|
||
| // ! Do not change or remove the code below | ||
| if (process.env.NODE_ENV !== 'test') { | ||
| main(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,61 +1,21 @@ | ||
| /*------------------------------------------------------------------------------ | ||
| Full description at: https://github.com/HackYourFuture/Assignments/tree/main/1-JavaScript/Week3#exercise-3-be-your-own-fortune-teller | ||
|
|
||
| Why pay a fortune teller when you can just program your fortune yourself? | ||
|
|
||
| 1. Create four arrays, `numKids`, `partnerNames`, `locations` and `jobTitles`. | ||
| Give each array five random values that have to do with the name of | ||
| the variable. | ||
|
|
||
| 2. Complete the function `selectRandomly`. This function should take an array | ||
| as a parameter and return a randomly selected element as its return value. | ||
|
|
||
| 3. Complete the function named `tellFortune` as follows: | ||
|
|
||
| - It should take four arguments (in the order listed): | ||
| * the array with the options for the number of children, | ||
| * the array with the options for the partner's name, | ||
| * the array with the options for the geographic location and | ||
| * the array with the options for the job title. | ||
| - It should use the `selectRandomly` function to randomly select values from | ||
| the arrays. | ||
| - It should return a string: "You will be a `jobTitle` in `location`, | ||
| married to `partnerName` with `numKids` kids." | ||
|
|
||
| 4. Call the function three times, passing the arrays as arguments. Use ` | ||
| console.log` to display the results. | ||
|
|
||
| Note: The DRY principle is put into practice here: instead of repeating the code to | ||
| randomly select array elements four times inside the `tellFortune` function | ||
| body, this code is now written once only in a separated function. | ||
| -----------------------------------------------------------------------------*/ | ||
|
|
||
| // This function should take an array as its parameter and return | ||
| // a randomly selected element as its return value. | ||
| function selectRandomly(/* TODO parameter(s) go here */) { | ||
| // TODO complete this function | ||
| function selectRandomly(arr) { | ||
| return arr[Math.floor(Math.random() * arr.length)]; | ||
|
Comment on lines
+2
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| } | ||
|
|
||
| export function tellFortune(/* TODO add parameter(s) here */) { | ||
| // TODO complete this function | ||
| export function tellFortune(numKids, partnerNames, locations, jobTitles) { | ||
| return `You will be a ${selectRandomly(jobTitles)} in ${selectRandomly( | ||
| locations | ||
| )}, married to ${selectRandomly(partnerNames)} with ${selectRandomly( | ||
| numKids | ||
| )} kids.`; | ||
|
Comment on lines
+6
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| } | ||
|
|
||
| function main() { | ||
| const numKids = [ | ||
| // TODO add elements here | ||
| ]; | ||
|
|
||
| const partnerNames = [ | ||
| // TODO add elements here | ||
| ]; | ||
|
|
||
| const locations = [ | ||
| // TODO add elements here | ||
| ]; | ||
|
|
||
| const jobTitles = [ | ||
| // TODO add elements here | ||
| ]; | ||
| const numKids = [0, 1, 2, 3, 4]; | ||
| const partnerNames = ["Alex", "Sam", "Taylor", "Jordan", "Casey"]; | ||
| const locations = ["Amsterdam", "Rotterdam", "Utrecht", "The Hague", "Eindhoven"]; | ||
| const jobTitles = ["developer", "designer", "teacher", "engineer", "chef"]; | ||
|
Comment on lines
+15
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
|
||
| console.log(tellFortune(numKids, partnerNames, locations, jobTitles)); | ||
| console.log(tellFortune(numKids, partnerNames, locations, jobTitles)); | ||
|
|
@@ -66,3 +26,9 @@ function main() { | |
| if (process.env.NODE_ENV !== 'test') { | ||
| main(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍