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

148
Views
I have to find the sum of odd numbers from 1 to n and it doesnt work

This is all i got but it doesnt work i dont know why

   Introduceti nr n
    <input type="text" name="sumofoddnumbers" onclick="Sum()"/>
    <button type="submit" name="button" onclick="Sum()">Click me!</button><br>


<script>
function Sum(n){
  let suma = 0;
  for(var i=1;i<=n;i+=2)
    suma=suma+i;
  return(suma)}
</script>
about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

En su función onclick, llama a "Sum()". Que pasa como parámetro la variable N para que entre en el ciclo de la función

Se especifica que se debe encontrar la manera de sumar los números impares de 1 a n, por ende la funci[on debe recibir n como parametro para saber hasta que numero hace la suma de impares

about 4 years ago · Santiago Gelvez Report

0

First, you missed the n parameter. if you are trying to pass input value then you have to do this...

 function Sum(n){ let suma = 0; for(var i=1;i<=n; i++){ if(i%2 != 0){ suma = suma + i } } document.getElementById('val').textContent=suma; }
 console.log(Sum(10))

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!