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_9 - Mohamed Abdalla - JavaScript - WEEK_1 #417
Open
Mohamed-Abdalla-1
wants to merge
6
commits into
CodeYourFuture:master
Choose a base branch
from
Mohamed-Abdalla-1:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7529056
Completed exercises and mandatory
Mohamed-Abdalla-1 ad5ad2c
magic ball
Mohamed-Abdalla-1 b97289c
Update 3-magic-8-ball.js
Mohamed-Abdalla-1 87baef2
Jest-extended library
Mohamed-Abdalla-1 e737e2b
adjust
Mohamed-Abdalla-1 12f1bc2
changed let to const
Mohamed-Abdalla-1 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
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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| // Use IntelliSense to learn about possible attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "type": "node", | ||
| "request": "launch", | ||
| "name": "Launch Program", | ||
| "skipFiles": [ | ||
| "<node_internals>/**" | ||
| ], | ||
| "program": "${workspaceFolder}/exercises/E-strings-concatenation/exercise.js" | ||
| } | ||
| ] | ||
| } |
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,3 @@ | ||
| console.log("Hello world"); | ||
|
|
||
| console.log ("Hello"); |
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 `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` | ||
| let message = `This is a string`; | ||
| let 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,9 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| let greeting="Hello, my name is"; | ||
|
|
||
| let name="Mohamed"; | ||
|
|
||
| let message=`${greeting} ${name}` | ||
|
|
||
| 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,6 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| console.log(message); | ||
| let name="Mohamed"; | ||
| let nameLength = name.length; | ||
|
|
||
| console.log(nameLength); |
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,10 @@ | ||
| const name = " Daniel "; | ||
|
|
||
|
|
||
| let greeting = "Hello, my name is"; | ||
|
|
||
|
|
||
| let message = `${greeting} ${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` | ||
| let numberOfStudents = 73; | ||
| let numberOfMentors = 17; | ||
| let totalNumber = numberOfMentors + numberOfStudents; | ||
|
|
||
| console.log(`Number of students: ${numberOfStudents}`) | ||
| console.log(`Number of mentors: ${numberOfMentors}`); | ||
| console.log(`Total number of students and mentors: ${totalNumber}`); | ||
|
|
||
|
|
||
|
|
||
|
|
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,11 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
|
|
||
| let totalNumber = numberOfMentors + numberOfStudents; | ||
|
|
||
| let percentageStudents = Math.round(numberOfStudents / totalNumber * 100); | ||
| let percentageMentors = Math.round(numberOfMentors / totalNumber * 100); | ||
|
|
||
| console.log(`Percentage students: ${percentageStudents}%`); | ||
|
|
||
| console.log(`Percentage mentors: ${percentageMentors}%`) |
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,7 +1,9 @@ | ||
| function halve(number) { | ||
| // complete the function here | ||
| let result =number/2; | ||
| return result; | ||
| } | ||
|
|
||
| var result = halve(12); | ||
| var result = halve(13); | ||
|
|
||
| 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,7 +1,9 @@ | ||
| function triple(number) { | ||
| // complete function here | ||
| let result = number*3; | ||
| return result; | ||
| } | ||
|
|
||
| var result = triple(12); | ||
| var result = triple(10); | ||
|
|
||
| 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
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,8 @@ | ||
| // Declare your function first | ||
|
|
||
| function divide (a,b) { | ||
| let result=a/b; | ||
| return result; | ||
| } | ||
| 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
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,10 @@ | ||
| // Declare your function first | ||
|
|
||
| function add (a,b) { | ||
| return a+b; | ||
| } | ||
|
|
||
| // Call the function and assign to a variable `sum` | ||
| let sum = add(13,124); | ||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,21 @@ | ||
| function upperCaseName(name) { | ||
| return name.toUpperCase(); | ||
| } | ||
|
|
||
| function greeting(name) { | ||
| return `HELLO ${upperCaseName(name)}`; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| var mentor1 = "Daniel"; | ||
| var mentor2 = "Irina"; | ||
| var mentor3 = "Mimi"; | ||
| var mentor4 = "Rob"; | ||
| var mentor5 = "Yohannes"; | ||
|
|
||
| console.log (greeting(mentor1)); | ||
| console.log(greeting(mentor2)); | ||
| console.log(greeting(mentor3)); | ||
| console.log(greeting(mentor4)); | ||
| console.log(greeting(mentor5)); |
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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| const { toBeOneOf } = require("jest-extended"); | ||
| /** | ||
|
|
||
| Let's peer into the future using a Magic 8 Ball! | ||
|
|
@@ -45,8 +46,34 @@ | |
|
|
||
| // This should log "The ball has shaken!" | ||
| // and return the answer. | ||
| let answers = [ | ||
| "It is certain.", | ||
| "It is decidedly so.", | ||
| "Without a doubt.", | ||
| "Yes - definitely.", | ||
| "You may rely on it.", | ||
| "As I see it, yes.", | ||
| "Most likely.", | ||
| "Outlook good.", | ||
| "Yes.", | ||
| "Signs point to yes.", | ||
| "Reply hazy, try again.", | ||
| "Ask again later.", | ||
| "Better not tell you now.", | ||
| "Cannot predict now.", | ||
| "Concentrate and ask again.", | ||
| "Don't count on it.", | ||
| "My reply is no.", | ||
| "My sources say no.", | ||
| "Outlook not so good.", | ||
| "Very doubtful.", | ||
| ]; | ||
| let answer = ""; | ||
|
|
||
| function shakeBall() { | ||
| //Write your code in here | ||
| console.log("The ball has shaken!"); | ||
| return answer = answers[Math.floor(Math.random() * answers.length)]; | ||
|
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. There's a lot going on in this line, could break it into several, similar to your 'good code' example above? |
||
| } | ||
|
|
||
| /* | ||
|
|
@@ -58,10 +85,47 @@ function shakeBall() { | |
|
|
||
| This function should expect to be called with any value which was returned by the shakeBall function. | ||
| */ | ||
| let positiveOrNegative = ""; | ||
|
|
||
| function checkAnswer(answer) { | ||
| //Write your code in here | ||
| switch (answer) { | ||
| case "It is certain.": | ||
| case "It is decidedly so.": | ||
| case "Without a doubt.": | ||
| case "Yes - definitely.": | ||
| case "You may rely on it.": | ||
| positiveOrNegative = "very positive"; | ||
| break; | ||
| case "As I see it, yes.": | ||
| case "Most likely.": | ||
| case "Outlook good.": | ||
| case "Yes.": | ||
| case "Signs point to yes.": | ||
| positiveOrNegative = "positive"; | ||
| break; | ||
| case "Reply hazy, try again.": | ||
| case "Ask again later.": | ||
| case "Better not tell you now.": | ||
| case "Cannot predict now.": | ||
| case "Concentrate and ask again.": | ||
| positiveOrNegative = "negative"; | ||
| break; | ||
| case "Don't count on it.": | ||
| case "My reply is no.": | ||
| case "My sources say no.": | ||
| case "Outlook not so good.": | ||
| case "Very doubtful.": | ||
| positiveOrNegative = "very negative"; | ||
| break; | ||
| } | ||
| return positiveOrNegative; | ||
| } | ||
|
|
||
| // shakeBall(); | ||
| // console.log(answer); | ||
| // checkAnswer("Very doubtful."); | ||
| // console.log(positiveOrNegative); | ||
| /* | ||
| ================================== | ||
| ======= TESTS - DO NOT MODIFY ===== | ||
|
|
@@ -101,7 +165,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.
Uh oh!
There was an error while loading. Please reload this page.