Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
Calculating average with prompt of an number

How can I make a function to find average from a number insert from prompt? Instead of an array of data.

It is different form all the tutorial on the site because the tutorial and solution here are having a set of data already but instead this question above wants us to calculate the sum of the input number form the prompt.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

for example:

const size = parseInt(prompt("insert number")) + 1;
if(size > 0){
  const arr = [...Array(size).keys()];
  const sum = arr.reduce(function(a, b) { return a + b; }, 0);
  alert(sum / size );
}
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!