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
za2-chifambawalter-javascript-core-1-coursework-week-1 #310
Closed
Closed
Changes from all commits
Commits
Show all changes
2 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
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,5 @@ | ||
| { | ||
| "editor.formatOnSave": true, | ||
| "editor.formatOnType": true, | ||
| "editor.formatOnPaste": true | ||
| } |
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 world"); | ||
| console.log("Hello world"); |
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,5 @@ | ||
| // Start by creating a variable `greeting` | ||
|
|
||
| var greeting = "Hello Walter"; | ||
| 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,4 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| let message = "Hello Walter"; | ||
| console.log(message); | ||
| console.log(typeof "hello walter"); |
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,5 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| let greeting = "Hello my name is"; | ||
| let _name = "Walter"; | ||
| 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,5 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| console.log(message); | ||
| var user_name = "Walter"; | ||
| var characters = user_name.length; | ||
| var output = "My name is "+user_name+" and is "+characters+" characters long." | ||
| console.log(output); |
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,3 @@ | ||
| const name = " Daniel "; | ||
|
|
||
| const myName = " Daniel "; | ||
| let message = myName.trim | ||
| 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,5 @@ | ||
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||
| let numberOfStudents=15; | ||
| let numberOfMentors = 8; | ||
| let result = numberOfMentors + numberOfStudents | ||
| console.log("The total number of students and mentors is" + (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,2 +1,7 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
| let total = numberOfStudents + numberOfMentors; | ||
| let student_percentage = numberOfStudents / total * 100; | ||
| let mentor_percentage = numberOfMentors / total * 100 | ||
| console.log("Percentage students: "+Math.round(student_percentage)+"%"); | ||
| console.log("Mentor students: "+Math.round(mentor_percentage)+"%"); |
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 | ||
| return number * 0.5; | ||
| } | ||
|
|
||
| var result = halve(12); | ||
| let result = halve(12); | ||
|
|
||
| console.log(result); | ||
| console.log(halve(9)); |
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,7 @@ | ||
| // 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,7 @@ | ||
| // Write your function here | ||
|
|
||
| function createGreeting(myName) { | ||
| return "hello, my name is" + myName; | ||
| } | ||
| 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,7 @@ | ||
| // Declare your function first | ||
|
|
||
| function add_two_numbers(a, b) { | ||
| return a + b; | ||
| } | ||
| // Call the function and assign to a variable `sum` | ||
|
|
||
| let sum = add_two_numbers(124, 13); | ||
| 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,7 @@ | ||
| // Declare your function here | ||
|
|
||
| function createLongGreeting(myName, age) { | ||
| return "Hello, my name is " + myName + " 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,41 @@ | ||
| // There are syntax errors in this code - can you fix it to pass the tests? | ||
|
|
||
| function addNumbers(a b c) { | ||
| return a + b + c; | ||
| function addNumbers(a ,b, c) { | ||
| return a + b + c; | ||
| } | ||
|
|
||
| function introduceMe(name, age) | ||
| return "Hello, my name is " + name "and I am " age + "years old"; | ||
|
|
||
| addNumbers(3, 4 ,6) | ||
| function introduceMe(name, age){ | ||
| return "Hello, my name is " + name +" and I am "+ age + " years old"; | ||
| } | ||
| introduceMe("Sonjide ", 27) | ||
| function getTotal(a, b) { | ||
| total = a ++ b; | ||
| total = a + b; | ||
|
|
||
| return "The total is total"; | ||
| return "The total is "+total; | ||
| } | ||
| getTotal(23,5) | ||
|
|
||
| /* | ||
| =================================================== | ||
| ======= TESTS - DO NOT MODIFY BELOW THIS LINE ===== | ||
|
|
||
| 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 1-syntax-errors` into your terminal | ||
| (Reminder: You must have run `npm install` one time before this will work!) | ||
|
|
||
| To run these tests type `node 1-syntax-errors.js` into your terminal | ||
| =================================================== | ||
| */ | ||
|
|
||
| test("addNumbers adds numbers correctly", () => { | ||
| expect(addNumbers(3, 4, 6)).toEqual(13); | ||
| }); | ||
| const util = require('util'); | ||
|
|
||
| test("introduceMe function returns the correct string", () => { | ||
| expect(introduceMe("Sonjide", 27)).toEqual( | ||
| "Hello, my name is Sonjide and I am 27 years old" | ||
| ); | ||
| }); | ||
| function test(test_name, actual, expected) { | ||
| let status; | ||
| if (actual === expected) { | ||
| status = "PASSED"; | ||
| } else { | ||
| status = `FAILED: expected: ${util.inspect(expected)} but your function returned: ${util.inspect(actual)}`; | ||
| } | ||
|
|
||
| console.log(`${test_name}: ${status}`); | ||
| } | ||
|
|
||
| test("getTotal returns a string describing the total", () => { | ||
| expect(getTotal(23, 5)).toEqual("The total is 28"); | ||
| }); | ||
| test("fixed addNumbers function - case 1", addNumbers(3, 4, 6), 13); | ||
| test("fixed introduceMe function", introduceMe("Sonjide", 27), "Hello, my name is Sonjide and I am 27 years old"); | ||
| test("fixed getTotal function", getTotal(23, 5), "The total is 28"); |
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.
Hey man remember that we should use let and const instead of var, so could you please replace your var with one of the two.
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.
mr Matho thank you brother