Регистрация
29 Янв 2013
Сообщения
98
Репутация
0
Спасибо
0
Монет
0
в задаче подразумевается отсутствие циклов

Задача 1

Давайте выведем на экран всю таблицу умножения. Объявите функцию printRow с одним параметром x, которая будет печатать на экран строку умножения на x. Например, если x == 1 то она напечатает 1 2 3 4 5 6 7 8 9, а если x == 2 то напечатает 2 4 6 8 10 12 14 16 18. Вызовите её 9 раз, передавая ей в качестве аргумента числа от 1 до 9.
 
const printRow = (x) => {
const row = [1, 2, 3, 4, 5, 6, 7, 8, 9];
console.log(row.map((e) => e * x).join(' '), '\n');
};

const printTable = () => {
const column = [1, 2, 3, 4, 5, 6, 7, 8, 9];
column.map((x) => printRow(x));
};

printTable();
 
function printRow(x) {
let row = "";
for (let i = 1; i <= 9; i++) {
row += x * i + " ";
}
console.log(row);
}

for (let i = 1; i <= 9; i++) {
printRow(i);
}
 
function printRow(x, y = 1) {
if (y > 9) return;

console.log(x * y);

printRow(x, y + 1);
}

function printTable(i = 1) {
if (i > 9) return;

console.log(`multiplication table for ${i}`);
printRow(i);
console.log('\n'); // for empty space between the tables

printTable(i + 1);
}

printTable();
 
Назад
Сверху