# Code challenge about Arrays and strings in pure Javascript

**URL:** <https://forum.freecodecamp.org/t/code-challenge-about-arrays-and-strings-in-pure-javascript/594037>\
**Category:** Curriculum Help\
**Created:** [February 22, 2023, 8:21pm UTC](https://forum.freecodecamp.org/t/code-challenge-about-arrays-and-strings-in-pure-javascript/594037 "2023-02-22T20:21:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joanarpcribeiroduart](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/joanarpcribeiroduart/32/306716_2.png) [@joanarpcribeiroduart](https://forum.freecodecamp.org/u/joanarpcribeiroduart)\
**Post date:** [February 22, 2023, 8:21pm UTC](https://forum.freecodecamp.org/t/code-challenge-about-arrays-and-strings-in-pure-javascript/594037/1 "2023-02-22T20:21:02Z")

</div>

I am a n00b, and am currently doing some pure Javascript challenges to enter a bootcamp.

We are going over **arrays** , and have learned specifically a few things to complete the hacking challenges, such as:

- Methods, such as: **pop()**, **push()** , **split(‘’)**, **join()** (or **join(’ ')** if we want to remove the commas),
- How to console log what’s inside arrays and concatenate the values with Strings.
- How to print certain array elements, as so:

```auto
var petShop = ['Puppies', 'Kitties', 'Hamsters', 'Snakes', 'Birds'];

console.log('In the second cage we have: ' + petShop[1]);

// prints 'In the second cage we have: Kitties'

```

- Array.length
- How to use for loops to print each of the elements of an array, like so:

```auto
var powerRangers = ['Red', 'Black', 'Yellow', 'Pink', 'Blue'];

for( var i = 0; i < powerRangers.length; i++){
    console.log(i + ':' + powerRangers[i]);
}

```

- we also went through if statements

**CHALLENGE**  
The challenge states:

Instructions

Copy the uncorrupted data in the array stored in targetDisk to the empty array newDisk (corrupted data looks like this: ø). Then print the contents of the disk to the terminal as a string.

To complete this task remember the arrays’ methods we have learned so far. (which are the ones I wrote above)

**MY CODE**

```auto
var targetDisk = ['E', 'ø', '-', 'C', 'ø', 'o', 'r', 'ø', 'ø', 'p', '\'', 'ø', 's', ' ', 'E', 'v', 'ø', 'i', 'ø', 'ø', 'l'];
var newDisk = [];
var corruptionSymbol = 'ø';

var phrase = targetDisk.join(' ');

console.log('This is the phrase: ' + phrase);

var newPhrase = phrase.split('ø');

console.log('This is the newPhrase: ' + newPhrase);

for( var i = 0; i < newPhrase.length; i++){
    newDisk.push(newPhrase[i]);
      //console.log(newDisk);
}

console.log('This is the newDisk: ' + newDisk.join(''));

```

**THE OUTPUT**

Code is incorrect.  
Your code is not up to fSociety standards, keep trying to improve it  
This is the phrase: E ø - C ø o r ø ø p ’ ø s E v ø i ø ø l  
This is the newPhrase: E , - C , o r , , p ’ , s E v , i , , l  
This is the newDisk: E - C o r p ’ s E v i l

* * *

I am thinking that it might be wrong because there are still spaces between the newDisk string - as you can see in the output.

Can someone help me understand what I am doing wrong? How can I remove those spaces between the letters in the final string and have something like so: E-Corp’s Evil

Thank you so much for your help!

---

<div class="post-metadata">

**Author:** ![camperextraordinaire](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@camperextraordinaire](https://forum.freecodecamp.org/u/camperextraordinaire)\
**Post date:** [February 22, 2023, 9:23pm UTC](https://forum.freecodecamp.org/t/code-challenge-about-arrays-and-strings-in-pure-javascript/594037/2 "2023-02-22T21:23:07Z")

</div>

> [@joanarpcribeiroduart](#):
>
> `var phrase = targetDisk.join(' ');`

For some reason you decided to join `targetDisk` array using space characters. This is the source of the space characters. There is no reason to do this. You can simply iterate through `targetDisk` using a `for` loop and only push elements that are not `'ø'` to the `newDisk` array. You will need some conditional logic to accomplish this.

---

<div class="post-metadata">

**Author:** ![joanarpcribeiroduart](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/joanarpcribeiroduart/32/306716_2.png) [@joanarpcribeiroduart](https://forum.freecodecamp.org/u/joanarpcribeiroduart)\
**Post date:** [February 22, 2023, 11:42pm UTC](https://forum.freecodecamp.org/t/code-challenge-about-arrays-and-strings-in-pure-javascript/594037/3 "2023-02-22T23:42:18Z")

</div>

Hi @camperextraordinaire ,  
Thank you so much for your feedback - I had some other tries commented out, and one of them was pretty close to what you described here - just missed a few elements, which made it not work, of course.

Here’s the solution that did work:

```auto
for( var i = 0; i < targetDisk.length; i++){
    if(targetDisk[i] !== corruptionSymbol){
        newDisk.push(targetDisk[i]);
	}
};

console.log(newDisk.join(''));

```

Thank you so much for your help! 🙂

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [August 24, 2023, 11:42am UTC](https://forum.freecodecamp.org/t/code-challenge-about-arrays-and-strings-in-pure-javascript/594037/4 "2023-08-24T11:42:31Z")

</div>

Closed on August 24, 2023, 11:42am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
