I am doing a JavaScript practice problem on Practice.it, and there's a question to print 2 rocket ships side by side.
I have printed one out but I can't figure out how to print the other rocket ship right next to the first one.
Also, is there way to do this using for loops?
function rocket(){
triangle();
line();
sides();
line();
console.log("|Rocket |");
console.log("| #1 |");
line();
sides();
line();
triangle();
}
function triangle(){
console.log(" / \\");
console.log(" / \\");
console.log(" / \\");
}
function line(){
console.log("+-------+");
}
function sides(){
console.log("| |");
}
rocket();
Output:
/ \
/ \
/ \
+-------+
| |
+-------+
|Rocket |
| #2 |
+-------+
| |
+-------+
/ \
/ \
/ \
A quick and dirty way would just be to concatenate each string with itself. So for every instance of console.log("+--------+")
use:
console.log("+--------+".repeat(2));
And just do this for each string.