
Dan B. answered 05/04/21
Experienced University Level Tutor in Software Engineering
Hi there! I hope this helps:
//Method header from the question
public static void displayNumber(int n) {
//Empty string for us to build and then display later
var str = "";
//here's a for loop that will iterate n times starting at 1
for(int i = 1; i <= n; i++){
//First we will build our string here
str = str + i + " ";
//If the current number is divisible by 7 then we need to move to the next line with a new line character
if(i % 7 == 0){
str = str + "\n";
}
}
//Then we've got our built string! if n is 5 it should be: "1 2 3 4 5 " now we just need to log it to the console.
//It wasn't specified where it needs to be displayed so I'm assuming it's the console.
console.log(str);
}