Solution text file should be less than xxx characters. You have xxx - Expected: true, instead got: false

I am working on my Codewars puzzle and it got close to the solution. Still I got the following errors:


`Solution text file should be less than 300 characters. You have 906 - Expected: true, instead got: false`

The task here was to return the multiple lines of Strings (aka lyrics) under the babyshark var, I Googled string concatenation, slice etc but my code is still error-ridden (see below). Any advice?

function babySharkLyrics(){
  
  var babyshark = `Baby shark, doo doo doo doo doo doo + 
Baby shark, doo doo doo doo doo doo
Baby shark, doo doo doo doo doo doo
Baby shark!
Mommy shark, doo doo doo doo doo doo
Mommy shark, doo doo doo doo doo doo
Mommy shark, doo doo doo doo doo doo
Mommy shark!
Daddy shark, doo doo doo doo doo doo
Daddy shark, doo doo doo doo doo doo
Daddy shark, doo doo doo doo doo doo
Daddy shark!
Grandma shark, doo doo doo doo doo doo
Grandma shark, doo doo doo doo doo doo
Grandma shark, doo doo doo doo doo doo
Grandma shark!
Grandpa shark, doo doo doo doo doo doo
Grandpa shark, doo doo doo doo doo doo
Grandpa shark, doo doo doo doo doo doo
Grandpa shark!
Let's go hunt, doo doo doo doo doo doo
Let's go hunt, doo doo doo doo doo doo
Let's go hunt, doo doo doo doo doo doo
Let's go hunt!
Run away,…`;
  var count = 1000;
  
  result = babyshark.slice(0, 1000);
  
  return result;
}

I recommend using string concatenation + or += and the .repeat method for strings.

var doo6 = " doo".repeat(6);
var babyshark = "";
babyshark += ("Baby shark," + doo6 + "\n").repeat(3) + "Baby shark!\n";
babyshark += ("Mommy shark," + doo6 + "\n").repeat(3) + "Mommy shark!\n"; 

and so on.

There are ways to make that code even shorter, like using arrays and loops, and string interpolation.

Also, you don’t actually need

  var count = 1000;
  
  result = babyshark.slice(0, 1000);
  
  return result;

because you can do

  return babyshark;

Thank you so much for all this :slight_smile: I’ll try them out next time I got access back to my PC.

I still got the same error message after I adopted your hints :confused:

The code looks like:
function babySharkLyrics(){
// your code here
var var6 = "doo ".repeat(6);
var babyshark = “”;
babyshark += (“Baby shark, " + var6 + " \n”).repeat(3) + “Baby shark!\n”;
babyshark += (“Mommy shark, " + var6 + " \n”).repeat(3) + “Mommy shark!\n”;
babyshark += (“Daddy shark, " + var6 + " \n”).repeat(3) + “Daddy shark!\n”;
babyshark += (“Grandma shark, " + var6 + " \n”).repeat(3) + “Grandma shark!\n”;
babyshark += (“Granpa shark, " + var6 + " \n”).repeat(3) + “Grandpa shark!\n”;
babyshark += (“Let’s go hunt, " + var6 + " \n”).repeat(3) + “Let’s go hunt!\n”;
babyshark += “Run away,…”;
console.log(babyshark);
}

The error stays;
Solution text file should be less than 300 characters. You have 664 - Expected: true, instead got: false

I didn’t say that I’d give you the answer for the whole challenge.
Think about how you would use loops (or arrays), and maybe string interpolation (string template literals) to redo parts of the code.

var emotion = "happy";
var str1 = "I am " + emotion + " to be here.";

is the same as:

var emotion = "happy";
var str = `I am ${emotion} to be here.`;

when using a literal for string interpolation.

Also, your solution should have a return in it instead of the console.log

Let me put it another way: I just wanted to tell you that my code has still errors. :slight_smile: I did not expect anyone to give me the whole answer/solution code. As you know the idea of Codewars is “practice” if I keep getting the solution code from anyone it won’t help my learning.

Anyway, thank you so much for giving me hints once again :slight_smile: Will try it out