Commit 426db68a authored by Nikolay Tarassenko's avatar Nikolay Tarassenko

Добавлено приложение quiz таблица умножения

parent df116351
// const userName = prompt('Как ваше имя?');
// alert(`Привет ${userName},\n\` как ваши дела?`);
const userErrors = [
[1, 0],
[2, 0],
[3, 0],
[4, 0],
[5, 0],
[6, 0],
[7, 0],
[8, 0],
[9, 0],
];
let corretAnswer = 0;
let wrongAnswer = 0;
let questionCount = 0;
const quizeMode = prompt('Choose difficult mode, enter easy,normal,hard,all')
.toLowerCase()
.trim();
switch (quizeMode) {
case 'easy':
{
alert('easy');
while (true) {
const firstRandomValue = Math.floor(Math.random() * 2 + 1);
const secondRandomValue = Math.floor(Math.random() * 2 + 1);
const userAnswer = prompt(
`What is ${firstRandomValue} * ${secondRandomValue} `
);
if (userAnswer === null) break;
let userNumber = parseInt(userAnswer);
while (isNaN(userNumber)) {
userNumber = parseInt(
prompt('You enter not a number, please enter number')
);
if (!isNaN(userNumber)) break;
}
questionCount++;
if (userNumber === firstRandomValue * secondRandomValue) {
corretAnswer++;
} else {
wrongAnswer++;
userErrors[firstRandomValue - 1][1]++;
if (firstRandomValue !== secondRandomValue) {
userErrors[secondRandomValue - 1][1]++;
}
}
}
const sortedErrors = userErrors.sort((a, b) => a[1] - b[1]).slice(-3);
let errorsMessage = '';
for (let i = 0; i < sortedErrors.length; i++) {
errorsMessage += `Multyply by ${sortedErrors[i][0]}: x ${sortedErrors[i][1]}\n`;
}
const messageResult =
`Question qty: ${questionCount}\n` +
`wrong answer qty: ${wrongAnswer}\n` +
`correct answer qty: ${corretAnswer}\n` +
errorsMessage;
alert(messageResult);
}
break;
case 'normal':
{
alert('normal');
while (true) {
const firstRandomValue = Math.round(Math.random() * (5 - 3) + 3);
const secondRandomValue = Math.round(Math.random() * (5 - 3) + 3);
const userAnswer = prompt(
`What is ${firstRandomValue} * ${secondRandomValue} `
);
if (userAnswer === null) break;
let userNumber = parseInt(userAnswer);
while (isNaN(userNumber)) {
userNumber = parseInt(
prompt('You enter not a number, please enter number')
);
if (!isNaN(userNumber)) break;
}
questionCount++;
if (userNumber === firstRandomValue * secondRandomValue) {
corretAnswer++;
} else {
wrongAnswer++;
userErrors[firstRandomValue - 1][1]++;
if (firstRandomValue !== secondRandomValue) {
userErrors[secondRandomValue - 1][1]++;
}
}
}
const sortedErrors = userErrors.sort((a, b) => a[1] - b[1]).slice(-3);
let errorsMessage = '';
for (let i = 0; i < sortedErrors.length; i++) {
errorsMessage += `Multyply by ${sortedErrors[i][0]}: x ${sortedErrors[i][1]}\n`;
}
const messageResult =
`Question qty: ${questionCount}\n` +
`wrong answer qty: ${wrongAnswer}\n` +
`correct answer qty: ${corretAnswer}\n` +
errorsMessage;
alert(messageResult);
}
break;
case 'hard':
{
alert('hard');
while (true) {
const firstRandomValue = Math.round(Math.random() * (9 - 1) + 1);
let secondRandomValue = Math.round(Math.random() * (9 - 1) + 1);
while (
secondRandomValue === 1 ||
secondRandomValue === 2 ||
secondRandomValue === 5
) {
secondRandomValue = Math.round(Math.random() * (9 - 1) + 1);
}
const userAnswer = prompt(
`What is ${firstRandomValue} * ${secondRandomValue} `
);
if (userAnswer === null) break;
let userNumber = parseInt(userAnswer);
while (isNaN(userNumber)) {
userNumber = parseInt(
prompt('You enter not a number, please enter number')
);
if (!isNaN(userNumber)) break;
}
questionCount++;
if (userNumber === firstRandomValue * secondRandomValue) {
corretAnswer++;
} else {
wrongAnswer++;
userErrors[firstRandomValue - 1][1]++;
if (firstRandomValue !== secondRandomValue) {
userErrors[secondRandomValue - 1][1]++;
}
}
}
const sortedErrors = userErrors.sort((a, b) => a[1] - b[1]).slice(-3);
let errorsMessage = '';
for (let i = 0; i < sortedErrors.length; i++) {
errorsMessage += `Multyply by ${sortedErrors[i][0]}: x ${sortedErrors[i][1]}\n`;
}
const messageResult =
`Question qty: ${questionCount}\n` +
`wrong answer qty: ${wrongAnswer}\n` +
`correct answer qty: ${corretAnswer}\n` +
errorsMessage;
alert(messageResult);
}
break;
case 'all':
alert('all');
break;
default:
alert('You enter invalid value, setting default mode all');
break;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment