Question

JavaScript Programming Assignment PLEASE NOTE:  You must create and call a main function, and if instructed include...

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

Homework Answers

Answer #1

// 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:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a C++ program to demonstrate thread synchronization. Your main function should first create a file...
Write a C++ program to demonstrate thread synchronization. Your main function should first create a file called synch.txt. Then it will create two separate threads, Thread-A and Thread-B. Both threads will open synch.txt and write to it. Thread-A will write the numbers 1 - 26 twenty times in nested for loops then exit. In other words, print 1 - 26 over and over again on separate lines for at least 20 times. Thread-B will write the letters A - Z...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT