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(" "); } } } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education