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:
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:
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
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!