-1
#Python Code
characters = "Hello World!"
print(characters * 4)  #it Will Print Hello World! 4 times

// Javascript Code
characters = "Hello World!"
console.log(characters * 4)
2
  • I don't know the reasoning why Python would allow this, but I'm not familiar with much of the philosophy of Python. In JavaScript this "doesn't work" simply because performing math on text makes no sense. Commented Sep 30, 2021 at 11:29
  • @David please, let's not start discuss JavaScript and "makes sense" :) Anyway, you can't argue that string * 4 does not work in JS because "performing math on text makes no sense" while JS allows string + 4 (which Python does not allow, BTW). It just that * is not defined in JS for string and integer operands, not that "it makes no sense" Commented Sep 30, 2021 at 11:39

2 Answers 2

1

In javascript you can use the inbuilt property 'repeat' of a string

characters = "Hello World!";
console.log(characters.repeat(4));
Sign up to request clarification or add additional context in comments.

Comments

0

You can use repeat().

const chorus = 'Hello World! ';
console.log(`${chorus.repeat(4)}`);

Edit: Use the other person's reply instead of mine, it's way simpler

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.