高级JavaScript模式创建问题

huangapple go评论75阅读模式
英文:

Advanced JavaScript Pattern Creation Problem

问题

I am working on a project 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. Here's what I have:

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

If I have one variable that is a horizontal line and one that is vertical, how would I put them next to each other?

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

英文:

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?

答案1

得分: 0

// 如果我正确理解你的问题,可能是这样的:

// 这些是创建的4个星星图案
const row = "* * * *\n";
const leftColumn = "*\n";
const middleColumn = "   *\n";
const twoColumns = "*     *\n";

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

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

// 写L
console.log(leftColumn + leftColumn + leftColumn + leftColumn + row);
英文:

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);

huangapple
  • 本文由 发表于 2023年3月3日 22:59:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75628652.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定