London-10-Afsha-Hossain-JavaScript-core-1-coursework-week1#503
Conversation
Completed the mandatory part and most of extras . Need help in the last task in extra.
|
|
||
| function calculateSalesTax() {} | ||
| function calculateSalesTax(price) { | ||
| return 1.20 * price; |
| ]; | ||
|
|
||
| function checkAnswer() { | ||
| if answer = "It is certain." || "It is decidedly so." || "Without a doubt." || "Yes - definitely." || "You may rely on it." { |
There was a problem hiding this comment.
What is the difference between = and ===
| ]; | ||
|
|
||
| function checkAnswer() { | ||
| if answer = "It is certain." || "It is decidedly so." || "Without a doubt." || "Yes - definitely." || "You may rely on it." { |
There was a problem hiding this comment.
check syntax of if loop. ex.
If (condition) {
return something
} if else (condition) {
return something
} else {
return
};
| */ | ||
| function checkAnswer(answer) { | ||
|
|
||
| const answer = [ |
There was a problem hiding this comment.
My advice, break answers array into four arrays with relevant name (arr positive[answers], negative[answers] and so on) and then join them into one using spread operator.
| "Very doubtful." | ||
| ]; | ||
|
|
||
| function checkAnswer() { |
There was a problem hiding this comment.
in this function you need to compare each answer with location in certain array. But in your loop you compare the array itself with the possible answer, so it's not gonna work.
| answerRandom = Math.floor(Math.random() * 16); | ||
| return answerRandom; |
There was a problem hiding this comment.
| answerRandom = Math.floor(Math.random() * 16); | |
| return answerRandom; | |
| answerRandom = allAnswers[Math.floor(Math.random() * allAnswers.length)]; | |
| return answerRandom; |
Here you get answerRandom from your array
There was a problem hiding this comment.
use console.log to meet the condition of one of comments This should log "The ball has shaken!"
| "It is certain.", | ||
| "It is decidedly so.", | ||
| "Without a doubt.", | ||
| "Yes - definitely.", | ||
| "You may rely on it.", |
There was a problem hiding this comment.
| "It is certain.", | |
| "It is decidedly so.", | |
| "Without a doubt.", | |
| "Yes - definitely.", | |
| "You may rely on it.", | |
| const veryPositive = [ "It is certain.", | |
| "It is decidedly so.", | |
| "Without a doubt.", | |
| "Yes - definitely.", | |
| "You may rely on it.", | |
| ] |
This is as an example of a child array
| "Outlook not so good.", | ||
| "Very doubtful." | ||
| ]; | ||
|
|
There was a problem hiding this comment.
| const allAnswers = [...veryPositive, ...positive, ans so on] |
check how works spread operator
| if answer = "It is certain." || "It is decidedly so." || "Without a doubt." || "Yes - definitely." || "You may rely on it." { | ||
| return "The answer is very positive: ${randomAnswer}"; |
There was a problem hiding this comment.
| if answer = "It is certain." || "It is decidedly so." || "Without a doubt." || "Yes - definitely." || "You may rely on it." { | |
| return "The answer is very positive: ${randomAnswer}"; | |
| if (veryPositive.includes(answer)) { | |
| return "very positive" | |
| } if else (positive.includes(answer)) { | |
| return .... |
you can continue yourself
I hope it's helpful. if you get stuck, write me in slack, or check my PR
|
|
||
| function convertToBRL() {} | ||
| function convertToBRL(price) { | ||
| price = price * 0.99 * 5.7; |
There was a problem hiding this comment.
-
when declaring a variable, must use const or let, otherwise it becomes a global variable which can cause a bug.
-
the variable name and parameter name should be different :)
| let goodCode = | ||
| const betterStartingValue = 2; | ||
| additionResult = betterStartingValue + 10; | ||
| multiplicationResult = additionResult * 2; |
There was a problem hiding this comment.
let's use const 🚀
const additionResult = betterStartingValue + 10;
const multiplicationResult = additionResult * 2;
…a few corrections based on the reviewers comments.
Completed the mandatory part and most of extras . Need help in the last task in extra.
Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in
HOW_TO_MARK.mdin the root of this repositoryYour Details
Homework Details
Notes
What did you find easy?
What did you find hard?
What do you still not understand?
Any other notes?