JavaScript Programming Assignment
PLEASE NOTE: You must create and call a main function, and if instructed include additional functions called by the main. Make sure to use ES6 style of keywords => instead of the older function and for local scope variables use the keyword let and not a keyword var. Make sure to follow the requirements and recheck before submitting.
PROJECT GOAL:
Write a program that is required to use nested loops to generate a triangle as shown in the sample run below. The program should begin by prompting the user to enter the number of lines in the triangle and output to the console to match the example below.
Hint: Each line will contain either "O" or " " (spaces) to align the output to appear right justified and process.stdout.write will print without a newline.
How many lines of the triangle?:6
OOOOOO
OOOOO
OOOO
OOO
OO
O
// Javascript program to generate a triangle
let readline = require('readline-sync'); // module for taking input
var main = () =>{
// input of the number of lines in the triangle
num_lines = parseInt(readline.question("Enter number
of lines in the triangle?: "));
let i,j; // loop variables
// nested loop to print the triangle
for(i=num_lines;i>0;i--)
{
for(j=0;j<i;j++)
process.stdout.write('O ');
process.stdout.write('\n');
}
}
// call the main function
main()
//end of program
Output:
Get Answers For Free
Most questions answered within 1 hours.