JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
</body>
</html>
JavaScript
const promt = (message = '') => window.prompt(message);
function getAnswerAnyway(defaultQuestion, repeatQuestion) {
const iter = (atempts = 2) => {
const question = atempts === 2 ? defaultQuestion : repeatQuestion;
let age = promt(question);
return age || iter(atempts - 1);
}
return iter(2);
}
function greeting() {
let name = getAnswerAnyway(
'Здравствуйте, как вас зовут?',
'Я же спрашиваю, как вас зовут?',
);
let age = getAnswerAnyway(
'Сколько вам лет?',
'Почему молчите? Возраст укажите',
);
alert(`Здравствуйте ${name}, вам ${age} лет.`);
}
greeting();