Skip to content

finish exercise-w6-arrays by xing #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,114 @@ const pokemons = [
const countThem = () => {
// print out, in a sentence, how many pokemons I have.
// like: "I have x pokemons!"
console.log(`I have ${pokemons.length} pokemons!`)
};

countThem()
console.log(`this is my first ${pokemons.at(0)} pokemons`)
console.log(`this is my favorite ${pokemons.at(-1)} pokemons`)

const orderThem = () => {
// order the pokemons alphabetically
//console.log(pokemons.sort())
};

// orderThem()

const flipThem = () => {
// reverse the order of the pokemons
//console.log(pokemons.reverse())
};

// flipThem()


const makeThemBig = () => {
// print the pokemons in UPPERCASE letters
// console.log(pokemons.map(item => item.toUpperCase()))
};

// makeThemBig()

const onlyTheBs = () => {
// only print the pokemons that starts with B
// console.log(pokemons.filter(item => item.startsWith("B")))
// console.log(pokemons.filter(item => item.charAt(0) === "B"))
// console.log(pokemons.filter(item => item.substring(0, 1) === "B"))
};

// onlyTheBs()


const notTheCs = () => {
// remove all pokemons that starts with C
// console.log(pokemons.filter(item => !item.startsWith("C")))
};

// notTheCs()

const nameAndIdThanks = () => {
// print out name and index of all pokemons
// like: number x - Squirtle

// Use forEach to iterate over the pokemons array
// pokemons.forEach((pokemon, index) => {
// console.log(`Number ${index + 1} - ${pokemon}`) // Print in the format: number x - PokémonName
// })
};

// nameAndIdThanks()

const catchPokemon = name => {
// add a pokemon with a name of your choice to the list,
// print the list so you see its there.
pokemons.push("XingBa")
console.log(pokemons)
console.log(`Now I have ${pokemons.length} pokemons!`)
};

catchPokemon()


const didICatchIt = name => {
// check the pokemons to see if a specific pokemon is in the array
// use includes() method, which checks if an array contains a specified element and returns true or false
// if (pokemons.includes(name)) {
// console.log (`${name} is catched!`)
// } else {
// console.log (`${name} is not catched!`)
// }
// Using indexOf() *********************
if (pokemons.indexOf(name) !== -1) {
console.log (`${name} is catched!`)
} else {
console.log (`${name} is not catched!`)
}
};

didICatchIt("Bua")
didICatchIt("XingBa")

const addInThirdPlace = () => {
// add the pokemon "Clefairy" in the third place of the array
// print the list so you see its there.
pokemons.splice(2,0,"Clefairy")
console.log(pokemons)
console.log(`Now I have ${pokemons.length} pokemons!`)
};

addInThirdPlace()

// ***BONUS***
const theLongestName = () => {
// find the pokemon with the longest name
let longestName = ""
pokemons.forEach(pokemon => {
if (pokemon.length > longestName.length) {
longestName = pokemon
}
})
console.log(`This pokemon has the longest name: ${longestName}`)
};

theLongestName()