Bucles en canvas con JavaScript

El dibujo en canvas se puede introducir en un bucle. Dibujemos varias líneas usando un bucle:

html<canvas width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet canvas = document.querySelector('canvas');
let ctx = canvas.getContext('2d');

for (let i = 1; i <= 10; i++) {
  ctx.moveTo(50, 15 * i);
  ctx.lineTo(150, 15 * i);
}

ctx.stroke();

Результат:

Problemas prácticos

Задание 1
Задание 2