logo CodeStepByStep logo

numberSquare

Language/Type: JavaScript for loops

Write a function named numberSquare that takes two integers as parameters, a min and a max, and prints the numbers in the range from min to max inclusive in a square pattern.

Each line of the square consists of a wrapping sequence of integers increasing from min and max. The first line begins with min, the second line begins with min + 1, and so on. When the sequence in any line reaches max, it wraps around back to min. For example, the call numberSquare(1, 5) should output the following:

12345
23451
34512
45123
51234

If may assume that min is greater than max, throw an exception with the message, "min value must not be greater than max value". Use console.log() to output each sequence on a new line.

Function: Write a JavaScript function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.