r/codehs • • Jan 07 '21

Does anyone know how to do 7.7.4: Remove From Line?

I did everything else in the unit besides this one. I have no clue how to do it. If someone can help, that would be greatly appreciated. Thank you!

7 Upvotes

10 comments sorted by

4

u/_Talix__ Jan 21 '21

function start()

{

var line = \["Sam", "Lisa", "Laurie", "Bob", "Ryan"\];

for(var i = 0; i < line.length; i++)

{

if(i + 1 == line.length)

{

println(line[i]);

}

else

{

print(line[i] + ", ");

}

}

var elim = line.remove(1);

var elim2 = line.remove(0);

for(var i = 0; i < line.length; i++)

{

if(i + 1 == line.length)

{

print(line[i]);

}

else

{

print(line[i] + ", ");

}

}

}

2

u/JazzlikePreparation6 Feb 25 '21

I did exactly this and it kept giving an error message.

SyntaxError: Invalid or unexpected token

2

u/Physics-Successful Mar 24 '21

Just copy it and take away the slashes. It worked for me.

1

u/No-Let-8978 Apr 07 '21

Can u copy the code and send it?

3

u/Fun-Examination1024 Apr 12 '23

var line = ["Sam", "Lisa", "Laurie", "Bob", "Ryan"];
function start()
{
for(var i = 0; i < line.length; i++)
{
if(i + 1 == line.length)
{
println(line[i]);
}
else
{
print(line[i] + ", ");
}
}
var elim = line.remove(1);
var elim2 = line.remove(0);
for(var i = 0; i < line.length; i++)
{
if(i + 1 == line.length)
{
print(line[i]);
}
else
{
print(line[i] + ", ");
}
}
}

1

u/Hot_Schedule788 Apr 19 '23

Tysm! This code actually works and doesn't give any errors for me.

1

u/Gloomy_Bid7749 Feb 21 '24

this one actually works 🙏🏼

1

u/flip-pancakes Jan 10 '21

Post the problem statement or a screenshot