英文:
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论