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(" "); } } } }
Operations
In mathematics and computer science, an operation is an event that is carried out to satisfy a given task. Basic operations of a computer system are input, processing, output, storage, and control.
Basic Operators
An operator is a symbol that indicates an operation to be performed. We are familiar with operators in mathematics; operators used in computer programming are—in many ways—similar to mathematical operators.
Division Operator
We all learnt about division—and the division operator—in school. You probably know of both these symbols as representing division:
Modulus Operator
Modulus can be represented either as (mod or modulo) in computing operation. Modulus comes under arithmetic operations. Any number or variable which produces absolute value is modulus functionality. Magnitude of any function is totally changed by modulo operator as it changes even negative value to positive.
Operators
In the realm of programming, operators refer to the symbols that perform some function. They are tasked with instructing the compiler on the type of action that needs to be performed on the values passed as operands. Operators can be used in mathematical formulas and equations. In programming languages like Python, C, and Java, a variety of operators are defined.
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 now
This is a popular solution!
Step by step
Solved 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.