Assessment required for JS Test your Skill_Strings

The assignment is at https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Test_your_skills:_Strings.

My solution to the four questions are

  1. https://jsfiddle.net/deeplee403/6c52qyze/3/
  2. https://jsfiddle.net/deeplee403/7bamdst9/10/
  3. https://jsfiddle.net/deeplee403/gnamqpcf/14/
  4. https://jsfiddle.net/deeplee403/L57q0os2/22/

Could you assess my work. Thank you.

Hello @Deepak_Tandan

Let’s have a look at your tasks:

  • Task 1: Correct :white_check_mark:
  • Task 2: Correct :white_check_mark: Bonus question: How could you extract the whole revisedQuote with slice()? const revisedQuote = quote.slice(???);
  • Task 3: Correct :white_check_mark:
  • Task 4: Correct :white_check_mark:

Congratulations! Amazing job :sunglasses:

All the best,
Michael

@mikoMK
thank you for the assessment.
about your bonus question - I first treated the substring as index, and then used index to slice it to the start of the original quote.

Sorry I don’t understand your answer. Maybe I asked the question wrong. Let’s try again! :smile:
You could replace your code

const name =  quote.slice('',index)
const revisedQuote = `${name} ${substring}.`;

with just const revisedQuote = quote.slice(???); and without using a template string. My bonus question is: “What needs to be written instead of the three question marks to achieve this?”

Hi I couldn’t yet find the answer to your question as I am really new to all this…
I have one more question though

This is the solution to test your skill of Arrays section which I had to look over at https://github.com/mdn/learning-area/blob/main/javascript/introduction-to-js-1/tasks/arrays/marking.md#task-3.

let myArray = [ “Ryu”, “Ken”, “Chun-Li”, “Cammy”, “Guile”, “Sakura”, “Sagat”, “Juri” ];

myArray.pop();

myArray.push(‘Zangief’);
myArray.push(‘Ibuki’);

myArray.forEach(function(element, index) {
let newElement = ${ element } (${index});
myArray[index] = newElement;
});

let myString = myArray.join(’ - ');

I could make sense of everything but not

myArray[index] = newElement;

could you help me

No worries. Because you solved everything perfectly I thought I ask another question, so you don’t get bored :grin: You don’t have to solve it.

This line is part of the loop and gets therefore executed for every element of the array. So let’s look what happens when we are in the first round of the loop:

  • element is "Ryu"
  • index is 0
  • One line above we create newElement. it’s defined as "Ryu (0)"

This means our line myArray[index] = newElement; becomes myArray[0] = "Ryu (0)" in the first round of the loop. So we replace the first element of the array ("Ryu") with a new element "Ryu (0)". This happens for every element of the array. In the end every name in the array is replace with name plus index in parentheses.

Generally, when you are unsure what happens in the code you could always write a value to the console. For example, you could put console.log(myArray[index]); above and below the line to see what happens or just put console.log(myArray); after the line to see how the whole array changes during the loop.

Was that understandable or can I help you more? :slightly_smiling_face:

1 Like

Thank you so much for the explanation. I am still trying to figure out the answer to the bonus question.

1 Like