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 - Irina Shilova - JavaScript - Core 1 - Week 1 #258
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
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,120 @@ | ||
| /*function isEven (num) { | ||
| if (num%2 === 0) | ||
| return true; | ||
| else | ||
| return false; | ||
|
|
||
| } | ||
|
|
||
| console.log(isEven(235))*/ | ||
|
|
||
| function isEven (num) { | ||
|
|
||
| } | ||
|
|
||
|
|
||
| /*function moreThanSixGoal (num1, num2) { | ||
| let total = num1 + num2; | ||
| if (total > 6) | ||
| return true; | ||
| else | ||
| return false; | ||
|
|
||
| } | ||
|
|
||
| console.log (moreThanSixGoal(2)); | ||
| console.log (moreThanSixGoal(8));*/ | ||
|
|
||
| /* | ||
| function numberChecker(num) { | ||
| if (num > 20) { | ||
| return `${num} is greater than 20`; | ||
| } else if (num === 20) { | ||
| return `${num} is equal to 20`; | ||
| } else if (num < 20) { | ||
| return `${num} is less than 20`; | ||
| } else { | ||
| return `${num} isn't even a number :(`; | ||
| } | ||
| } | ||
|
|
||
| console.log(numberChecker(10)); | ||
| console.log(numberChecker(56)); | ||
|
|
||
|
|
||
| function yourMood(message) { | ||
| if (message === "happy") { | ||
| return "Good job, you're doing great!"; | ||
| } else if (message ==="sad") { | ||
| return "Every cloud has a silver lining"; | ||
| } else if (typeof message === "number") { | ||
| return "Beep beep boop" | ||
| } else { | ||
| return "I'm sorry, I'm still learning about feelings!"; | ||
| } | ||
| } | ||
|
|
||
| console.log(yourMood("happy")); | ||
| console.log(yourMood("sad")); | ||
| console.log (yourMood("sasdfasdf")); | ||
| */ | ||
|
|
||
| /*let num = 10 | ||
| num > 5 && num < 15 | ||
| num < 10 || num === 10 | ||
| false || true | ||
| !true | ||
| let greaterThan5 = num > 5 | ||
| !greaterThan5 | ||
| !(num === 10) | ||
|
|
||
| function checkUsername (userName, userType) { | ||
| if (userName[0] === userName[0].toUppercase() && userName.length > 5 && userName < 10) { | ||
| return "Username valid"; | ||
| } else if (userType === "admin" || userType === "manager") { | ||
| return "Username valid"; | ||
| } else { | ||
| return "Username invalid"; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| console.log(checkUsername("Irina", "admin")); | ||
| */ | ||
|
|
||
| /* | ||
| const fruits = ["banana", "apple", "strawberry", "kiwi", "fig", "orange"]; | ||
| console.log(fruits[2]); | ||
| console.log(fruits[3]); | ||
| console.log(fruits[5]); | ||
| console.log(fruits[0]); | ||
| console.log(fruits[-3]); | ||
| console.log(fruits[8]); | ||
|
|
||
| fruits[6] = "peach"; | ||
|
|
||
| console.log(fruits); | ||
|
|
||
| fruits[10] = "pear"; | ||
| console.log(fruits); | ||
| */ | ||
|
|
||
| const products = ["smart phones", "chargers", "laptops", "monitors", "printers", "keyboards", "mice"]; | ||
|
|
||
| function numberOfProducts(products) { | ||
| return products.length; | ||
| } | ||
|
|
||
| function inStock(myProducts, nameOfProduct) { | ||
| for (let i = 0; i < myProducts.length; i++) { | ||
|
|
||
| if (nameOfProduct === myProducts[i]) { | ||
| return true | ||
| } else { | ||
| return false | ||
| } | ||
|
|
||
| } | ||
| } | ||
|
|
||
| console.log(inStock(products, "mice")); |
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 @@ | ||
| console.log("Hello world"); | ||
|
|
||
|
|
||
|
|
||
| console.log(12345); |
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` | ||
|
|
||
| let 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,5 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| let message = "This is a string"; | ||
| console.log(message); | ||
| let messageType = typeof(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,6 @@ | ||
| // Start by creating a variable `message` | ||
| let greetingStart = "Hello! My name is "; | ||
| let myName = "Irina"; | ||
| let 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,6 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| let myName = "Irina"; | ||
| let nameLength = myName.length; | ||
| let message = "Hello! My name is " + myName + " and my Name is " + nameLength + " 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,3 +1,8 @@ | ||
| const name = " Daniel "; | ||
|
|
||
| let message = "My name is " + name + " and my name is 6 characters long." | ||
| console.log(message); | ||
| let nameTrim = name.trim(); | ||
|
|
||
| let message2 = "My name is " + nameTrim + " and my name is 6 characters long"; | ||
| console.log(message2); | ||
|
|
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,8 @@ | ||
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||
| let numberOfStudents = 8; | ||
| let numberOfMentors = 15; | ||
| 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,14 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
|
|
||
| let totalNumber = numberOfMentors + numberOfStudents; | ||
|
|
||
| let percentOfStudents = numberOfStudents * 100 / totalNumber; | ||
| let percentOfMentors = numberOfMentors * 100 / totalNumber; | ||
|
|
||
|
|
||
|
|
||
| let roughPerSt = Math.round(percentOfStudents); | ||
| let roughPerMent= Math.round(percentOfMentors); | ||
| console.log("Percentage students: " + roughPerMent + "%"); | ||
| console.log("Percentage mentors: " + roughPerSt + "%"); |
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,10 @@ | ||
| function halve(number) { | ||
| // complete the function here | ||
| return number / 2; | ||
| } | ||
|
|
||
| var result = halve(12); | ||
|
|
||
| console.log(result); | ||
| console.log(halve(6)); | ||
|
|
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 | ||
| return number*3; | ||
| } | ||
|
|
||
| var result = triple(12); | ||
|
|
||
| console.log(result); | ||
| console.log(triple(5)); |
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,4 +1,7 @@ | ||
| // Declare your function first | ||
| function divide(a, b) { | ||
| return a/b; | ||
| } | ||
|
|
||
| var result = divide(3, 4); | ||
|
|
||
|
|
||
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 sumNumbers (a, b) { | ||
| return a+b; | ||
| } | ||
| // Call the function and assign to a variable `sum` | ||
|
|
||
| var sum = sumNumbers (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
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 |
|---|---|---|
|
|
@@ -16,26 +16,32 @@ | |
| the final result to the variable goodCode | ||
| */ | ||
|
|
||
| function add() { | ||
|
|
||
| function add(a, b) { | ||
| return a+b; | ||
| } | ||
|
|
||
| function multiply() { | ||
|
|
||
| function multiply(a, b) { | ||
| return a*b; | ||
| } | ||
|
|
||
| function format() { | ||
|
|
||
| function format(a) { | ||
| return "£"+a; | ||
| } | ||
|
|
||
| const startingValue = 2; | ||
|
|
||
| // Why can this code be seen as bad practice? Comment your answer. | ||
| let badCode = | ||
| // too many functions, difficult to understand; | ||
| format (multiply(add(startingValue, 10), 2)); | ||
|
Contributor
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. Looks like the test is failing because we're not assigning a value to the variable badCode. Can you think of how to fix this? |
||
|
|
||
|
|
||
| /* BETTER PRACTICE */ | ||
|
|
||
| let goodCode = | ||
| let sum = add(startingValue, 10); | ||
| let mult = multiply(sum, 2); | ||
|
|
||
|
|
||
| let goodCode = format(mult); | ||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== | ||
| There are some Tests in this file that will help you work out if your code is working. | ||
|
|
||
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,16 +1,15 @@ | ||
| // The syntax for this function is valid but it has an error, find it and fix it. | ||
|
|
||
| function trimWord(word) { | ||
| return wordtrim(); | ||
| return word.trim(); | ||
| } | ||
|
|
||
| function getStringLength(word) { | ||
| return "word".length(); | ||
| return word.length; | ||
| } | ||
|
|
||
| function multiply(a, b, c) { | ||
|
Contributor
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. Did you get a chance to look at this multiply function? It looks like you will still need to return a value here.
Author
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. Yes, now I fixed the errors |
||
| a * b * c; | ||
| return; | ||
| return a * b * c; | ||
| } | ||
|
|
||
| /* | ||
|
|
||
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.
Looks like the tests are failing here because this function is not returning a value. Any idea how you might fix this?