Concept explainers
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(" ");
}
}
}
}
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
So the histogram isn't showing in my
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.
So the histogram isn't showing in my
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.
- In JavaScript, how can you validate a user’s input to make sure it is both a number and between 20 and 100?arrow_forwardPlease &-. Write a Java program to check if a given string is a palindrome or not. A palindrome is a word, phrase, number, or other sequence of characters that reads the same backward as forward, ignoring spaces, punctuation, and capitalization. For example, "racecar" and "Madam" are palindromes, while "hello" and "Java" are not. Your program should take a string as input and return true if it's a palindrome, and false otherwise. Ik.?arrow_forwardHelp me debug this exercise using Javaarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education