This repository was archived by the owner on Jan 14, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 475
London Class 8 - Harsheek Thanki - JavaScript Core 1 - Week 1 #281
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| console.log("Hello world"); | ||
| console.log("hello world, I am learning to be a developer!"); | ||
| console.log("hello world, I am learning everyday"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // Start by creating a variable `greeting` | ||
| const greeting = "Hello world"; | ||
|
|
||
| console.log(greeting); | ||
| console.log(greeting); | ||
| console.log(greeting); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // Start by creating a variable `message` | ||
| const message = "This is a string"; | ||
| const messageType = typeof message; | ||
|
|
||
| console.log(message); | ||
| console.log(messageType); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| const greetingStart = "Hello, my name is "; | ||
| const myName = "Harsheek"; | ||
|
|
||
| const message = greetingStart + myName; | ||
|
|
||
| console.log(message); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| console.log(message); | ||
| const message = "Harsheek"; | ||
|
|
||
| console.log( | ||
| `My name is ${message} and my name is ${message.length} characters long` | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| const name = " Daniel "; | ||
|
|
||
| const message = `My name is ${name.trim()} and my name is ${ | ||
| name.trim().length | ||
| } characters long`; | ||
|
|
||
| console.log(message); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,12 @@ | ||
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||
|
|
||
| const numberOfStudents = 15; | ||
| const numberOfMentors = 8; | ||
|
|
||
| console.log(`Number of students: ${numberOfStudents}`); | ||
|
|
||
| console.log(`Number of mentors: ${numberOfMentors}`); | ||
|
|
||
| console.log( | ||
| `Total number of students and mentors: ${numberOfStudents + numberOfMentors}` | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,14 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
|
|
||
| console.log( | ||
| `Percentage students: ${Math.round( | ||
| (numberOfStudents / (numberOfMentors + numberOfStudents)) * 100 | ||
| )}%` | ||
| ); | ||
|
|
||
| console.log( | ||
| `Percentage mentors: ${Math.round( | ||
| (numberOfMentors / (numberOfMentors + numberOfStudents)) * 100 | ||
| )}%` | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| function halve(number) { | ||
| // complete the function here | ||
| return number / 2; | ||
| } | ||
|
|
||
| var result = halve(12); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| function triple(number) { | ||
| // complete function here | ||
| return number * 3; | ||
| } | ||
|
|
||
| var result = triple(12); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| // Declare your function first | ||
|
|
||
| function divide(a, b) { | ||
| return a / b; | ||
| } | ||
|
|
||
| var result = divide(3, 4); | ||
|
|
||
| console.log(result); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| // Write your function here | ||
|
|
||
| function createGreeting(name) { | ||
| return `Hello, my name is ${name}`; | ||
| } | ||
|
|
||
| var greeting = createGreeting("Daniel"); | ||
|
|
||
| console.log(greeting); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| // Declare your function first | ||
| function sumNumbers(a, b) { | ||
| return a + b; | ||
| } | ||
|
|
||
| let sum = sumNumbers(13, 124); | ||
| // Call the function and assign to a variable `sum` | ||
|
|
||
| console.log(sum); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| // Declare your function here | ||
|
|
||
| function createLongGreeting(name, age) { | ||
| return `Hello, my name is ${name} and I'm ${age} years old`; | ||
| } | ||
|
|
||
| const greeting = createLongGreeting("Daniel", 30); | ||
|
|
||
| console.log(greeting); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |
| and have different levels of positivity or negativity. | ||
|
|
||
| Below are the possible answers: | ||
|
|
||
| ## Very positive | ||
| It is certain. | ||
| It is decidedly so. | ||
|
|
@@ -43,10 +43,50 @@ | |
| Very doubtful. | ||
| */ | ||
|
|
||
| // This should log "The ball has shaken!" | ||
| // and return the answer. | ||
| const veryPositive = [ | ||
| "It is certain.", | ||
| "It is decidedly so.", | ||
| "Without a doubt.", | ||
| "Yes - definitely.", | ||
| "You may rely on it.", | ||
| ]; | ||
|
|
||
| const positive = [ | ||
| "As I see it, yes.", | ||
| "Most likely.", | ||
| "Outlook good.", | ||
| "Yes.", | ||
| "Signs point to yes.", | ||
| ]; | ||
|
|
||
| const negative = [ | ||
| "Reply hazy, try again.", | ||
| "Ask again later.", | ||
| "Better not tell you now.", | ||
| "Cannot predict now.", | ||
| "Concentrate and ask again.", | ||
| ]; | ||
|
|
||
| const veryNegative = [ | ||
| "Don't count on it.", | ||
| "My reply is no.", | ||
| "My sources say no.", | ||
| "Outlook not so good.", | ||
| "Very doubtful.", | ||
| ]; | ||
|
|
||
| // This should log "The ball has shaken!" | ||
| // and return the answer. | ||
| function shakeBall() { | ||
| //Write your code in here | ||
| const allAnswers = [ | ||
| ...veryPositive, | ||
| ...positive, | ||
| ...negative, | ||
| ...veryNegative, | ||
| ]; | ||
| return allAnswers[Math.round(Math.random() * allAnswers.length)]; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -55,11 +95,18 @@ function shakeBall() { | |
| - positive | ||
| - negative | ||
| - very negative | ||
|
|
||
| This function should expect to be called with any value which was returned by the shakeBall function. | ||
| */ | ||
| function checkAnswer(answer) { | ||
| //Write your code in here | ||
| if (veryPositive.includes(answer)) { | ||
| return "very positive"; | ||
| } else if (positive.includes(answer)) { | ||
| return "positive"; | ||
| } else if (negative.includes(answer)) { | ||
| return "negative"; | ||
| } else { | ||
| return "very negative"; | ||
| } | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -68,7 +115,7 @@ function checkAnswer(answer) { | |
|
|
||
| There are some Tests in this file that will help you work out if your code is working. | ||
|
|
||
| To run the tests for just this one file, type `npm test -- --testPathPattern 3-magic-8-ball` into your terminal | ||
| To run these tests type `npm run extraTo run the tests for just this one file, type `npm run extra-tests -- --testPathPattern 3-magic-8-ball` into your terminal | ||
|
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. You need to change the package.json if you want to run all tests. See Marina's work for the changes on the 3-magic-8-ball.js and package.json |
||
| (Reminder: You must have run `npm install` one time before this will work!) | ||
| ================================== | ||
| */ | ||
|
|
@@ -101,7 +148,9 @@ test("magic 8 ball returns different values each time", () => { | |
| ); | ||
| } | ||
|
|
||
| let seenPositivities = new Set(Array.from(seenAnswers.values()).map(checkAnswer)); | ||
| let seenPositivities = new Set( | ||
| Array.from(seenAnswers.values()).map(checkAnswer) | ||
| ); | ||
| if (seenPositivities.size < 2) { | ||
| throw Error( | ||
| "Expected to random answers with different positivities each time shakeBall was called, but always got the same one" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Thank you so much for your resubmission and I should have found out it much earlier! Nice and quality work as before. Refer to line 80, the function should log "The ball has shaken" to console when it is called