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 7 - Laura M - JavaScript Core 1 - Week 1 #42
Closed
Closed
Changes from all commits
Commits
Show all changes
5 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 |
|---|---|---|
| @@ -1 +1,7 @@ | ||
| // Various console.log messages at the same time | ||
| console.log("Hello world"); | ||
| console.log(5); // Numbers on their own won't return errors as they are a different type of data | ||
| console.log("Hello World. I just started learning JavaScript!"); | ||
| console.log("Returned to this exercise and changed this message!"); | ||
| console.log("Sometimes I spent too long getting bored"); | ||
| // Noticed that error messages appear on the terminal when words are not passed as strings (with quotation marks) |
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 `greeting` | ||
| // First tried the basic way: three separate times console.log(greeting); and then made a for-loop to try an alternative | ||
|
|
||
| console.log(greeting); | ||
| var greeting = "Aqui estoy!"; | ||
|
|
||
| for (i = 0; i < 3; i++) { | ||
| 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` | ||
|
|
||
| console.log(message); | ||
| // Then another variable to store the data type and finally log it to the console | ||
| var message = "This is a string data type"; | ||
| var 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,12 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| console.log(message); | ||
| // I tried this task first with variables in an individual form, but then decided to put them all in a function | ||
|
|
||
| function getGreeting(name) { | ||
| var greeting = "Hola"; | ||
| var courtesy = ", ¿cómo estás hoy?"; | ||
| var message = greeting + " " + name + courtesy; | ||
| return message; | ||
| } | ||
| var name = "Laurita"; | ||
| console.log(getGreeting(name)); |
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,18 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| console.log(message); | ||
| // I first tried it with variables (line 5, 6, 13) and then -after the functions exercises, made a function here too (lines 8 to 13) | ||
|
|
||
| // var myName = 'Laurita'; | ||
| // var myGreeting = 'My name is ' + myName + ' and my name is ' + myName.length + ' characters long'; | ||
|
|
||
| function getGreeting(name) { | ||
| var myGreeting = | ||
| "My name is " + | ||
| name + | ||
| " and my name is " + | ||
| name.length + | ||
| " characters long"; | ||
| return myGreeting; | ||
| } | ||
| var name = "Laurita"; | ||
| console.log(getGreeting(name)); | ||
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,13 @@ | ||
| // There are two variables, one to store a name plus the other one to store a message | ||
| // The .trim() method was applied to the name to reduce the unnecessary whitespace | ||
|
|
||
| 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
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,11 @@ | ||
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||
|
|
||
| // Some variables were created to store numbers and a sentence, which then was logged to the console | ||
|
|
||
| let numberOfStudents = 30; | ||
| let numberOfMentors = 10; | ||
|
|
||
| let numberOfAdults = | ||
| "The total amount of adults is " + (numberOfStudents + numberOfMentors); | ||
|
|
||
| console.log(numberOfAdults); |
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,2 +1,17 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
|
|
||
| // Variables created to generate the percentages and then the messages expected, which were then logged to the console | ||
|
|
||
| var numberOfAdults = numberOfMentors + numberOfStudents; | ||
|
|
||
| var percentageStudents = (numberOfStudents * 100) / numberOfAdults; | ||
| var percentageMentors = (numberOfMentors * 100) / numberOfAdults; | ||
|
|
||
| var totalStudents = | ||
| "Percentage of students: " + Math.round(percentageStudents) + "%"; | ||
| var totalMentors = | ||
| "Percentage of mentors: " + Math.round(percentageMentors) + "%"; | ||
|
|
||
| console.log(totalStudents); | ||
| console.log(totalMentors); |
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,13 @@ | ||
| function halve(number) { | ||
| // complete the function here | ||
| // Complete the function here | ||
| let half = number / 2; | ||
| return half; | ||
| } | ||
|
|
||
| var result = halve(12); | ||
|
|
||
| // Called the function various times | ||
|
|
||
| console.log(result); | ||
| console.log(halve(4)); | ||
| console.log(halve(1458690980)); |
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,11 @@ | ||
| function triple(number) { | ||
| // complete function here | ||
| // Completed function here to trebble a number and called it several times | ||
| let trebbledNum = number * 3; | ||
| return trebbledNum; | ||
| } | ||
|
|
||
| var result = triple(12); | ||
|
|
||
| console.log(result); | ||
| console.log(triple(39)); | ||
| console.log(triple(1)); |
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,9 +1,11 @@ | ||
| // Complete the function so that it takes input parameters | ||
| function multiply() { | ||
| function multiply(num1, num2) { | ||
| // Calculate the result of the function and return it | ||
| return num1 * num2; | ||
| } | ||
|
|
||
| // Assign the result of calling the function the variable `result` | ||
| var result = multiply(3, 4); | ||
|
|
||
| // Call the variable to show the value returned with the above function | ||
| 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,11 @@ | ||
| // Declare your function first | ||
| function divide(num1, num2) { | ||
| // Write the block of code inside the curly braces | ||
| return num1 / num2; | ||
| } | ||
|
|
||
| // Store the value of this function on a variable | ||
| var result = divide(3, 4); | ||
|
|
||
| // Call the variable | ||
| 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,11 @@ | ||
| // Write your function here | ||
| // Write your function here with the block of code inside the curly braces | ||
| function createGreeting(name) { | ||
| let myGreeting = "Hello, my name is " + name; | ||
| return myGreeting; | ||
| } | ||
|
|
||
| // Store the value in a variable | ||
| var greeting = createGreeting("Daniel"); | ||
|
|
||
| // Call the variable | ||
| 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,8 @@ | ||
| // Declare your function first | ||
|
|
||
| function mySum(num1, num2) { | ||
| let sum = num1 + num2; | ||
| return sum; | ||
| } | ||
| // Call the function and assign to a variable `sum` | ||
|
|
||
| console.log(sum); | ||
| let totalSum = mySum(13, 124); | ||
| console.log(totalSum); |
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,13 @@ | ||
| // Declare your function here | ||
| function myGreeting(name, age) { | ||
| let myName = "Hello, my name is " + name; | ||
| let myAge = " and I am " + age + " years old."; | ||
| let fullGreeting = myName + myAge; | ||
| return fullGreeting; | ||
| } | ||
|
|
||
| const greeting = createLongGreeting("Daniel", 30); | ||
| // Store the value in a variable | ||
| const greeting = myGreeting("Daniel", 30); | ||
|
|
||
| // Call the variable | ||
| 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 was deleted.
Oops, something went wrong.
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,18 @@ | ||
| // Option A [I had help to do this task, because I couldn't work it out by myself] | ||
|
|
||
| // First, created a function that calculated the percentage and round it | ||
| function getPercentage(subset, total) { | ||
| let percentage = Math.round((subset * 100) / total); | ||
| return percentage; | ||
| } | ||
| // After that, created another function that generated sentences using the percentage's function above | ||
| function getMessage(numberOfStudents, numberOfMentors) { | ||
| let total = numberOfStudents + numberOfMentors; | ||
| let studentPercentage = getPercentage(numberOfStudents, total); | ||
| let mentorPercentage = getPercentage(numberOfMentors, total); | ||
| let studentMessage = "Percentage of students: " + studentPercentage + "%"; | ||
| let mentorMessage = "Percentage of mentors: " + mentorPercentage + "%"; | ||
| return studentMessage + "\n" + mentorMessage; | ||
| } | ||
| // Called the last function to generate the sentences expected | ||
| console.log(getMessage(16, 30)); |
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,19 @@ | ||
| // Option B [I had help to do this task, because I couldn't work it out by myself] | ||
|
|
||
| // Created two separate functions | ||
| function getPercentage(subset, total) { | ||
| let percentage = Math.round((subset * 100) / total); | ||
| return percentage; | ||
| } | ||
| function getMessage(group, percentage) { | ||
| let message = "Percentage of " + group + ": " + percentage + "%"; | ||
| return message; | ||
| } | ||
| // Created variables to store values from the functions and call them for the students | ||
| let studentsPercentage = getPercentage(16, 46); | ||
| let studentsMessage = getMessage("students", studentsPercentage); | ||
| console.log(studentsMessage); | ||
| // Created variables to store values from the functions and call them for the mentors | ||
| let mentorsPercentage = getPercentage(30, 46); | ||
| let mentorsMessage = getMessage("mentors", mentorsPercentage); | ||
| console.log(mentorsMessage); |
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,18 @@ | ||
| // Option C | ||
|
|
||
| // Created a function with several variables that when called would return the expected output | ||
| function doPercentage(mentors, students) { | ||
| let allStudents = students; | ||
| let allMentors = mentors; | ||
| let allAdults = allStudents + allMentors; | ||
| let percentageStudents = (allStudents * 100) / allAdults; | ||
| let percentageMentors = (allMentors * 100) / allAdults; | ||
| let allPercentagesS = | ||
| "Percentage of students: " + Math.round(percentageStudents) + "%."; | ||
| let allPercentagesM = | ||
| "Percentage of mentors: " + Math.round(percentageMentors) + "%."; | ||
| let allPercentages = allPercentagesS + allPercentagesM; | ||
| return allPercentages; | ||
| } | ||
|
|
||
| console.log(doPercentage(16, 30)); |
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 @@ | ||
| // I got rid of the original list of variables and made it into an array below | ||
|
|
||
| // Created a nested function, the first one turns letters upper case and the second one displays the greeting to the mentors | ||
| function capitalisedString(message) { | ||
| let capitalisedShoutOut = message.toUpperCase(); | ||
| return capitalisedShoutOut; | ||
| } | ||
| function shoutOut(theMentors) { | ||
| for (i = 0; i < theMentors.length; i++) { | ||
| let shoutOut = "Hello " + theMentors[i]; | ||
| let capitalisedShoutOut = capitalisedString(shoutOut); | ||
| console.log(capitalisedShoutOut); | ||
| } | ||
| } | ||
| let theMentors = ["Daniel", "Irina", "Mimi", "Rob", "Yohannes"]; | ||
| shoutOut(theMentors); | ||
| // Once you specify the array of names, you can use the function (line 22) |
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.
Great Job! As a challenge, you can make use of template literals to tidy up the code and make it easier to read. This link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals and video: https://youtu.be/NgF9-pdTDGs are quite useful - should you need them.
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! It auto-formatted that way on save :-)