Home javascript Help write a program that asks the user with his name and...

Help write a program that asks the user with his name and displays text greetings to the console

Author

Date

Category

Help write a program that asks the user with his name and displays text congratulations into the console. To do this, use the While or For cycle.

Happy Birthday to You

Happy Birthday to You

Happy Birthday, Dear $ Name

Happy Birthday to You

Create 3 identical lines to me for strength, but how to insert a line with the name between them, I do not understand. My code:

Let Name = Prompt ('What is Your Name?' ');
Let str = '';
for (i = 1; i & lt; = 3; i ++) {
  STR + = 'Happy Birthday to You \ n';
}
Console.log (STR);

and yes, sorry, I’m bottom: (


Answer 1

let str = '';
For (i = 1; i & lt; = 4; i ++) {
  if (i == 3) STR + = 'Happy Birthday, Dear $ Name \ n'
  ELSE STR + = 'Happy Birthday to You \ n';
}
Console.log (STR);

Answer 2

function congratulate () {
    Let username = Prompt ('Enter your name!');
    For (Let i = 0; i & lt; = 3; i ++) {
      Let Message = (i === 2)? UserName: 'You';
      Console.log (`Happy Birthday, Dear $ {Message}!`);
    }
  }

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions