The code is a histogram using stars (astericks), I need to take user input (using readline.sync) and the out put shows in rows the astericks and the columns are the numbers that where typed in going straight down, at the end after entering the zero to stop the program. It goes from 1-100 for the number that can be entered by the user if they want to quit they must enter 0. I am very confused on the looping system when it comes to arrays and my book doesn't help me very well. My array needs to start at index 0, and add 1 to the index. And I was told to use the max function. I was also told to not over complicate the histogram, the histogram display only involves printing an asterick for the number of times a number is contained in the array. This is what I have at the moment, and I'm still working on it.   const readlineSync = require('readline-sync'); let arr =[]; let num = readlineSync.question("Enter a number between 1 and 100, or enter 0 to exit: "); while (num !== "0") { //while loop console.log("The number you entered is " + num); num++; } for (let i = 0; i <= 100; i++) { //for loop if (num >= 0 && num <= 100) { //if statement arr.push(num); if else (num ===i) { console.log(("* ".repeat(i) else{ console.log(" "); } } } }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 19PE
icon
Related questions
icon
Concept explainers
Question

I am writing code for javascript. The code is a histogram using stars (astericks), I need to take user input (using readline.sync) and the out put shows in rows the astericks and the columns are the numbers that where typed in going straight down, at the end after entering the zero to stop the program. It goes from 1-100 for the number that can be entered by the user if they want to quit they must enter 0. I am very confused on the looping system when it comes to arrays and my book doesn't help me very well. My array needs to start at index 0, and add 1 to the index. And I was told to use the max function. I was also told to not over complicate the histogram, the histogram display only involves printing an asterick for the number of times a number is contained in the array.

This is what I have at the moment, and I'm still working on it.

 

const readlineSync = require('readline-sync');
let arr =[];
let num = readlineSync.question("Enter a number between 1 and 100, or enter 0 to exit: ");

while (num !== "0") { //while loop
console.log("The number you entered is " + num);
num++;
}

for (let i = 0; i <= 100; i++) { //for loop
if (num >= 0 && num <= 100) { //if statement
arr.push(num);
if else (num ===i) {
console.log(("* ".repeat(i)
else{
console.log(" ");
}
}
}
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

So the histogram isn't showing in my program when I type 0, it just says invalid input and continues on with the code. I see it works on your side, but I need it to stop the code completely and show the stars for the numbers inputed.

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

I see now how the histogram works, but the issue I'm having is if I put in the number 3 it only shows * (1 astrick) and I need it to match the index correctly.

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Operators
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr