Hi,
I’ve been doing online tutorials e.g MDN, JS hero, Sololearn & completed the first two sections of freecodecamp… but I’ve not really done any challenges and put what ive learnt into action from scratch.
I’ve started doing some problems today and feel like I’ve not learnt anything!
I’ve got visual code editor & code runner.
My first challenge is to list everything in an array.
so
function animals(arr){
var animalString = "";
for (var i = 0; i < arr. length; i++) {
return animalString += arr[i];
}
}
console.log(animals(["cat","dog","human","whale","seal"]));
I’d like to return
cat
dog
human
whale.
Or: cat,dog,human,whale.
What I don’t understand is how to write:
let cars = ["Tesla", "Ferrari", "Lamborghini", "Audi"];
for(let i = 0; i < cars.length; i++) {
console.log(cars[i]);
}
As a function that will be displayed in the VC studio.
But right now all i get is cat…
this is part of a bigger challange:
Write a function that accepts an array of strings. Return the longest string.
I have looked at the solution and can see it is:
function longestString1(arr) {
var longest = ''; // Step 0
for (var i = 0; i < arr.length; i++) { // Step 1
if (arr[i].length > longest.length) { // Step 2 & 3
longest = arr[i]; // Step 4
}
}
return longest; // Step 5
I just cant understand how arr[i] is stored/ listed to then work compare it.
Thats why im trying to figure out how to just make an array from the list.
God! Coding its like 1 step forward, 2 steps back!!
Hope you can help!
Also, does anyone ever set up a buddy system for low cost / free help!
Thanks x

