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}!`);
}
}