From 8843c2f254049c1d171f0e30091e65fd1bb28c08 Mon Sep 17 00:00:00 2001 From: Sihakom Date: Wed, 4 Jan 2023 16:01:48 -0800 Subject: [PATCH 1/2] finished sprint 1 challenge --- index.js | 84 ++++++++++++++++++++++++++++++++++------------- package-lock.json | 4 +-- 2 files changed, 63 insertions(+), 25 deletions(-) diff --git a/index.js b/index.js index a9560baa3..b28dcac7b 100644 --- a/index.js +++ b/index.js @@ -209,16 +209,18 @@ Practice accessing data above by console.log-ing following items: //(1) Name of the first artist (0th index) in the array - +console.log(`task 1a:`, artists[0].name); //(2) Bio of the third artist (2nd index) in the array - +console.log(`task 1b:`, artists[2].bio); /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 2 (not auto tested): πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ (no function needed) There is a typo in your dataset 😱 The 9th artist, Vincent Van Gogh is currently Vincent Van Dough. Fix this issue and console.log() to check your work. */ +artists[10].name = `Vincent Van Gogh`; +console.log(`task 2:`, artists[10].name); /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 3: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ @@ -230,10 +232,10 @@ Use getArtistByIndex to do the following: 🌟 EXAMPLE: if getArtistByIndex is invoked with the artists array and the number 0, it will return `the artist at index 0 is Amedeo Modigliani` */ -function getArtistByIndex(/*Your Code Here*/) { - /*Your Code Here*/ +function getArtistByIndex(artists, index) { + return `the artist at index ${artists[index].id} is ${artists[index].name}`; } - +console.log(`task 3:`,getArtistByIndex(artists, 0)); /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 4: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ @@ -244,11 +246,19 @@ Use listOfNames to do the following: 🌟 EXAMPLE of return: ["Amedeo Modigliani", "Vasiliy Kandinskiy", "Diego Rivera"....] */ -function listOfNames(/*Your Code Here*/) { - /*Your Code Here*/ +function listOfNames (artists){ + const justNames =[]; + + for(let i = 0; i < artists.length; i++) { + if(artists[i].id > -1){ + justNames.push(artists[i].name); + + } + } + return justNames } - +console.log(`task 4:`, artists); /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 5: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Use removeArtist to do the following: @@ -259,12 +269,17 @@ Use removeArtist to do the following: 5. Return the resulting copied array 🌟 EXAMPLE: if removeArtist is invoked with the artists array and the number 0, it will return the resulting array with Amedeo Modigliani removed from our dataset. */ -function removeArtist(/*Your Code Here*/) { - /*Your Code Here*/ -} +function removeArtist(artists,number){ + const artistRemove = [...artists]; + + artistRemove.splice(number,1); + return artistRemove; +} + +console.log(`task 4:`, removeArtist(artists, 0)); /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 6: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Use addArtist to do the following: 1. Receive the artist array as an argument passed from the FIRST parameter @@ -281,9 +296,11 @@ Use addArtist to do the following: 5. Add the newly created object to the copied array, then return the copied array 🌟 EXAMPLE: Invoking addArtist(artists, 'John Doe', '1988-2022', 'Full Stack Development', 'African American', 'I have a background in customer service at Big Retail Chain. I am attending BloomTech to become a Frontend Developer.') should return the artists array with the above object added to the end of the array. */ -function addArtist(/*Your Code Here*/) { - /*Your Code Here*/ +function addArtist(artists, name, years, genre, nationality, bio){ + artists.push({name, years, genre, nationality, bio}); + return artists; } +console.log(`task 6:`, addArtist(artists, 'John Doe', `1988-2022`, `Full Stack Development`, `African American`, `I have a background in customer service at Big Retail Chain. I am attending BloomTech to become a Frontend Developer.`)); @@ -295,9 +312,19 @@ Use lotsOfArt to do the following: 🌟 EXAMPLE: lotsOfArt(artists) will return ["Amedeo Modigliani", "Rene Magritte", ... "Albrecht DΓΌrer"] */ -function lotsOfArt(/*Your Code Here*/) { - /*Your Code Here*/ +function lotsOfArt(array) { + const artistsPainting = []; + + for(let i = 0; i < artists.length; i++) { + if(artists[i].paintings > 100){ + artistsPainting.push(array[i].name) + + } + } + return artistsPainting + } +console.log(`task 7:`,artists) @@ -310,12 +337,17 @@ Use artistInfo to do the following: 🌟 EXAMPLE: Invoking artistInfo(artists, 'Frida Kahlo') will return: "Frida Kahlo de Rivera (Spanish pronunciation: [ˈfΙΎiΓ°a ˈkalo]; born Magdalena Carmen Frida Kahlo y CalderΓ³n; 6 July 1907 – 13 July 1954) was a Mexican artist who painted many portraits, self-portraits and works inspired by the nature and artifacts of Mexico. Inspired by the country's popular culture, she employed a naΓ―ve folk art style to explore questions of identity, postcolonialism, gender, class and race in Mexican society. Her paintings often had strong autobiographical elements and mixed realism with fantasy. In addition to belonging to the post-revolutionary Mexicayotl movement, which sought to define a Mexican identity, Kahlo has been described as a surrealist or magical realist.Born to a German father and a mestiza mother, Kahlo spent most of her childhood and adult life at her family home in CoyoacΓ‘n, La Casa Azul, now known and publicly accessible as the Frida Kahlo Museum. She was disabled by polio as a child. Until a traffic accident at age eighteen caused lifelong pain and medical problems, she had been a promising student headed for medical school. During her recovery, she returned to her childhood hobby of art with the idea of becoming an artist." */ - -function artistInfo(/*Your Code Here*/){ - /*Your Code Here*/ +function artistInfo(array, name){ + const artistBio = []; + for(let i = 0; i < array.length; i++){ + if(artists[i].name === name){ + artistBio.push(array[i].bio) +} + } + return artistBio[0] } - +console.log(`task 8:`, artistInfo(artists, `Frida Kahlo`)); /* πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Task 9: πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€πŸš€ Use artistByCountry to do the following: @@ -327,11 +359,17 @@ Use artistByCountry to do the following: 🌟 EXAMPLE: Invoking artistByCountry(artists, 'Spanish') will return: [ 'Salvador Dali', 'Pablo Picasso', 'Francisco Goya'] */ -function artistByCountry(/*Your Code Here*/){ - /*Your Code Here*/ -} - +function artistByCountry(array, nationality){ + const filteredArtists = []; + for(let i = 0; i < artists.length; i++) { + if(artists[i].nationality === nationality) { + filteredArtists.push(array[i].name); + } + } + return filteredArtists; +} +console.log(`task 9:`,artistByCountry(artists, `Spanish`)) /* ***** END OF TASKS ***** */ diff --git a/package-lock.json b/package-lock.json index 48103f21c..0f48f45e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "codegraded-project-js", - "version": "0.0.8", + "version": "0.0.9", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "codegraded-project-js", - "version": "0.0.8", + "version": "0.0.9", "devDependencies": { "@babel/core": "7.17.5", "@babel/plugin-transform-runtime": "7.17.0", From 588b205996f7df4e14b540246c7a9350735c45a7 Mon Sep 17 00:00:00 2001 From: Sihakom Date: Wed, 4 Jan 2023 16:11:54 -0800 Subject: [PATCH 2/2] Create a CodeGrade submission