0

I am working on a project from my for fun, and I was asked the question "Write a program to output the letters H, T and L as created by * characters. Create four variables that store * patterns and use ONLY THOSE to output the letters."

So what I have to do is create text in the console looking like this

*          *
*          *
*          *
************
*          *
*          *
*          *

First I had to figure out how to create a vertical line stored in a variable. It took me a while, but I did it with the "/n" function. I got it, but can't figure out the rest of the problem. i ever  :

var side1 = "*********"
var side2 = "*"+ "\n" +"*"+ "\n" +"*"+ "\n" +"*"+ "\n" +"*"+ "\n" +"*"+ "\n" +"*"+ "\n" +"*"+ "\n" +"*"
console.log(side2)

If I one variable which is a horizontal line, and one that is vertical, how would I put them next to eachother?

This is really random because I keep on deleting and trying new things. Any ideas?

  • you only have 3 letters to output and 4 vars to store them in, so one letter per var with an extra? You might also look into [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) and [string methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat) that might be useful – pilchard Mar 03 '23 at 15:02
  • So you need a variable to hold star with left and right star. You need a variable to hold center of row star and and a variable to hold the line. And a variable to hold the start of line star. So your T would be `full line + center line (x 6)` and H would be `startEnd (x3) + full line + startEnd (x3)` – epascarello Mar 03 '23 at 15:06
  • If I one variable which is a horizontal line, and one that is vertical, how would I put them next to eachother? – Viraj_Bagga Mar 03 '23 at 15:07
  • You concatenate the strings. – epascarello Mar 03 '23 at 15:08
  • How would you put them next to another instead on one on top – Viraj_Bagga Mar 03 '23 at 15:13
  • had you have a look [here](https://stackoverflow.com/q/39983648/1447675)? – Nina Scholz Mar 03 '23 at 15:41
  • Does this answer your question? [How can I write ASCII art for text(using any language)?](https://stackoverflow.com/questions/39983648/how-can-i-write-ascii-art-for-textusing-any-language) – pilchard Mar 03 '23 at 16:20

1 Answers1

0

If I interpreted your question correctly, maybe something like this:

// These are the 4 star patterns created
const row = "* * * *\n";
const leftColumn = "*\n";
const middleColumn = "   *\n";
const twoColumns = "*     *\n";

// write H
console.log(twoColumns + twoColumns + row + twoColumns + twoColumns);

// write T
console.log(row + middleColumn + middleColumn + middleColumn + middleColumn);

// write L
console.log(leftColumn + leftColumn + leftColumn + leftColumn + row);
alph
  • 179
  • 1
  • 8