-
-
Notifications
You must be signed in to change notification settings - Fork 475
wm3/halla_Sulaiman-JavaScript-core1-week1 #202
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,6 @@ | ||
| console.log("Hello world"); | ||
| console.log("Hello World. I just started learning JavaScript!."); | ||
| //console.log(Hello World. I just started learning JavaScript!.); // got a SyntaxError for this one . | ||
| console.log("44"); | ||
| console.log(44); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // Start by creating a variable `greeting` | ||
| const greeting = "Good morning js"; | ||
|
|
||
| console.log(greeting); | ||
| console.log(greeting); | ||
| console.log(greeting); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| const message = "this is a string" | ||
| console.log(message); | ||
| console.log(typeof(message)); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // Start by creating a variable `message` | ||
|
|
||
| let greetingStart = "Good morning, my name is "; | ||
| const myName = "Halla"; | ||
| let message = greetingStart + myName; | ||
| console.log(message); | ||
| console.log(greetingStart + myName); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,16 @@ | ||
| // Start by creating a variable `message` | ||
| let myName = " Halla "; | ||
| let message = myName.length; | ||
| let aboutName = `My name is Halla and my name is ${message} characters long`; | ||
| let aboutName1 = | ||
| "My name is Halla and my name is " + message + " characters long"; | ||
| let myNewName = myName.trim(); | ||
| let message1 = myNewName.length; | ||
|
Halla-S marked this conversation as resolved.
|
||
| let aboutName2 = | ||
| "My name is Halla and my name after trim is " + message1 + " characters long"; | ||
|
|
||
| console.log(aboutName); | ||
| console.log(aboutName1); | ||
| console.log(aboutName2); | ||
| console.log(message); | ||
| console.log(myName); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| const name = " Daniel "; | ||
|
|
||
| console.log(message); | ||
| const myName = " Daniel "; | ||
| let myNewName = myName.trim(); | ||
| let message1 = myNewName.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. I'd like to see a more explicit variable name for this. Just so you can read the script and see exactly what this variable does, something like
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. You are right , thank you . |
||
| let aboutmyName = | ||
| "My name is Daniel and my name after trim is " + message1 + " characters long"; | ||
| console.log(aboutmyName); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| // Start by creating a variables `numberOfStudents` and `numberOfMentors` | ||
| const numberOfStudents = 15; | ||
| const numberOfMentors = 8; | ||
| const total = 23; | ||
| console.log(total); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,7 @@ | ||
| var numberOfStudents = 15; | ||
| var numberOfMentors = 8; | ||
| const numberOfStudents = 15; | ||
| const numberOfMentors = 8; | ||
| const studentPercent = Math.round((15 / 23) * 100); | ||
| const mentorsPercent = Math.round((8 / 23) * 100); | ||
|
|
||
| console.log(`Student Percentage: ${studentPercent}%`); | ||
| console.log(`Mentors Percentage: ${mentorsPercent}%`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| function halve(number) { | ||
| // complete the function here | ||
| return number / 2; | ||
| } | ||
|
|
||
| var result = halve(12); | ||
| const result = halve(12); | ||
|
|
||
| console.log(result); | ||
| console.log(halve(24)); | ||
| console.log(halve(44)); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| function triple(number) { | ||
| // complete function here | ||
| return number * 3; | ||
| } | ||
|
|
||
| var result = triple(12); | ||
|
|
||
| const result = triple(12); | ||
| triple(3); | ||
| console.log(result); | ||
| console.log(triple(3)); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| // Complete the function so that it takes input parameters | ||
| function multiply() { | ||
| // Calculate the result of the function and return it | ||
| function multiply(a,b) { | ||
| return(a*b); | ||
| } | ||
|
|
||
| // Assign the result of calling the function the variable `result` | ||
| var result = multiply(3, 4); | ||
| const result = multiply(3, 4); | ||
|
|
||
| console.log(result); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| // Declare your function first | ||
|
|
||
| var result = divide(3, 4); | ||
| function divide(a, b) { | ||
| return a / b; | ||
| } | ||
| const result = divide(3, 4); | ||
|
|
||
| console.log(result); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| // Write your function here | ||
|
|
||
| var greeting = createGreeting("Daniel"); | ||
| function createGreeting(name){ | ||
| return "Good morning " + name ; | ||
| } | ||
| let greeting = createGreeting("Daniel"); | ||
|
|
||
| console.log(greeting); | ||
| console.log(createGreeting("Halla")); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| // Declare your function first | ||
|
|
||
| function adding(a, b) { | ||
| return a + b; | ||
| } | ||
| const sum = adding(13, 124); | ||
| // Call the function and assign to a variable `sum` | ||
|
|
||
| console.log(sum); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,8 +45,34 @@ | |
|
|
||
| // This should log "The ball has shaken!" | ||
| // and return the answer. | ||
|
|
||
| function shakeBall() { | ||
| //Write your code in here | ||
| expectedAnswers = [ | ||
|
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. This variable is missing a const or let declaration
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. Thank you Kate .As you can see , I declared it first outside of the function which makes it global . Then I changed my mind and moved it to the inside of the function without declaration , just trying to see if this would make it global from the inside of the function to be able to use it in the other function . tried both ways and both work . |
||
| "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.", | ||
| ]; | ||
| console.log("The ball has shaken!"); | ||
| let random1 = Math.floor(Math.random() * 20); | ||
| let answer = expectedAnswers[random1]; | ||
| return answer; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -59,7 +85,15 @@ function shakeBall() { | |
| 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 (expectedAnswers.indexOf(answer) <= 4) { | ||
| return "very positive"; | ||
| } else if (expectedAnswers.indexOf(answer) <= 9) { | ||
| return "positive"; | ||
| } else if (expectedAnswers.indexOf(answer) <= 14) { | ||
| return "negative"; | ||
| } else { | ||
| return "very negative"; | ||
| } | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -101,7 +135,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" | ||
|
|
||
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.
I'd like to see a more explicit variable name, while this works perfectly, it's harder to manage and read
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