Hi guys. I’ve been studying for a couple of week on this website Basic JavaScript and Object Oriented Programming. I’m attempting a coding challenge but it’s getting quite stressful and i can’t solve few functions.
So far i created this by the challenge request:
function createRiver(name, continent, lengthInKilometers) {
var object = {
"name" : name,
"continent" : continent,
"lengthInKilometers" : lengthInKilometers,
logRiver: function() {
console.log("The " + this.name + " river is " + this.lengthInKilometers + " kilometers long.");
}
}
return object
}
Then i had to push inside an array using the function some values of rivers. Having this:
var rivers = [];
var amazon = createRiver("Amazon", "South America", 6575);
var danube = createRiver("Danube", "Europe", 2850);
var ganges = createRiver("Ganges", "Asia", 2704);
var mekong = createRiver("Mekong", "Asia", 4350);
var mississippi = createRiver("Mississippi", "North America", 3730);
var nile = createRiver("Nile", "Africa", 6650);
var volga = createRiver("Volga", "Europe", 3530);
rivers.push(amazon, danube, ganges, mekong, mississippi, nile, volga);
It’s now asking to create 2 functions which i have no idea how to create.
getRiverByName - this function expects a string as an argument and returns the object in the rivers array whose name property is equal to the string that is passed to it (if there is one).
getRiversByContinent - this function expects a string as an argument and returns an array containing the objects in the rivers array whose continent properties are equal to the string that is passed to it.
Everything should be done without using ES6. I hope someone can really help me out!
Thanks in advance.