Rahwa Ghebremichael London-8 JS-1 Week-3 - #21
Conversation
DelroyGayle
left a comment
There was a problem hiding this comment.
Great work, Rahwa. Your hard work is an inspiration to me, and I am confident, it is to others.
Keep Going On!
Thank you.
| // TODO | ||
| let arr = []; | ||
| let i = 0; | ||
| while (i % 2 === 0 && n > 0 && n > arr.length) { |
There was a problem hiding this comment.
Hello Rahwa
Regarding this function I believe you ought to have another look.
Your output should be one string with commas e.g. 0,2,4
See if you can redo this function with a 'string' in mind. You want to build a string from "" and add even numbers to this string until 'n' is reached.
| let newClicks = []; | ||
|
|
||
| for (let i = 0; i < allArticleTitles.length; i++) { | ||
| for (let letter of allArticleTitles[i]) { |
There was a problem hiding this comment.
Hi Rahwa, as we are discovering there are many different ways of doing the same thing in JavaScript.
See if you a Google a solution whereby you can determine whether a character is a number using 'two' comparisons only!
In future, that method, will save you some typing!
:) :)
| sum += CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS[i][j]; | ||
| } | ||
| newAverage.push( | ||
| (sum / CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS[i].length).toFixed(2) * |
There was a problem hiding this comment.
As an alternative multiply the number by 100, then Math.round() it; then divide by 100
That way, you don't have to convert a number to a string , then multiply by 1 to convert it to a number again
| // TODO | ||
| let newPriceChange = []; | ||
| for (let i = 0; i < closingPricesForAllStocks.length; i++) { | ||
| newPriceChange.push((closingPricesForAllStocks[i][4] - closingPricesForAllStocks[i][0]).toFixed(2) * 1); |
There was a problem hiding this comment.
See my above comment regarding Math.round()
| // TODO | ||
| highestPrice =[]; | ||
| for(let i=0; i < closingPricesForAllStocks.length; i++) { | ||
| let highestNum = closingPricesForAllStocks[i].sort(function(a,b){ |
mahsa2
left a comment
There was a problem hiding this comment.
Nice job. It's great that you've spent time finishing your assignment, one day it comes to fruit 👍 💯 🥇
We finish the rest of the review on our next 1-1 session :)
|
|
||
| } | ||
|
|
||
| return arr.toString(); // changes the numbers to strings |
There was a problem hiding this comment.
function evenNumbers(n) {
let counter = 0;
let evenNum = 0;
while (counter < n) {
console.log(evenNum);
evenNum += 2
counter++;
}
}
The above prints every value on a different line. As an exercise let do this to print them as a comma separated string:
- Keep track of all the even numbers in the loop (hint: use array)
- After loop, console.log the array using the
join: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join
| // TODO - Write for loop code here | ||
| for(i=0; i < WRITERS.length; i++) { | ||
| console.log(WRITERS[i] + " " + "is " + AGES[i] + " "+ "years old."); | ||
| } |
There was a problem hiding this comment.
let i=0 ...- " years old"
`${WRITERS[i]} is ${AGES[i]} years old`
|
|
||
| for(tubes of tubeStations) { | ||
| console.log(tubes); | ||
| } |
| let result = str.toUpperCase(); | ||
| for(letter of result) { | ||
| console.log(letter); | ||
| } |
|
|
||
| } | ||
| while(number <= 50) | ||
| return number; |
mahsa2
left a comment
There was a problem hiding this comment.
Pretty good job Rahwa 💯 🥇 👍
So happy to see you've worked on the extra questions too
| } | ||
|
|
||
| return newString; | ||
| } |
| letter === "8"|| | ||
| letter === "9") { | ||
| newClicks.push(allArticleTitles[i]) | ||
| } |
There was a problem hiding this comment.
I like that you've solved the problem correctly with the ways you knew 🥇
There is a function isNaN that can check if a string is not a number, which can help to do this step for you.
| // TODO | ||
| let newAverage =[] | ||
| let sum = 0; | ||
| for (let i = 0; i < CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS.length; i++) { |
There was a problem hiding this comment.
In the function, instead of using CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS, we need to use the parameter closingPricesForAllStocks, so that we can call the function for different arrays of prices.
| input= input*i; | ||
| console.log(input) | ||
| } | ||
| return input; |
| } | ||
|
|
||
| } | ||
| return bookTitles; |
There was a problem hiding this comment.
👍 It's great that you've solved the problem by adding the highest rating manually. I am so happy you started looking into the extra exercises too.
For finding the highest rating with the code (so that you can use the function with other types of books array and rating that 4.8 is not their highest rating), primary a for loop over books before what you wrote, can find the max rating first, then you can replace it with the 4.8 in your above code. For that, you can use a variable with the max rating of 0 (minimum rating) and then if you find a book with more ratings than that, you update the maximum rating till you visit all the book ratings.
| } | ||
|
|
||
|
|
||
| return fib; |
No description provided.