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

210
Views
Cuente el número de ocurrencias de 7 en un número dado por el usuario
while (a) { b.push(a % 10); a = Math.floor(a / 10); if (b == 7) { n = n + 1; } console.log("<br><br>number of 7's:" + n); }

Esto es lo que se me ocurrió. La salida es uno de los números tiene siete; si no, entonces cero. Quiero que el programa cuente la cantidad de veces que aparece siete en un número.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Puede convertir el número en una cadena y luego contar cuántas veces un carácter = 7:

 let n = 7326577 let cnt = 0; let strN = '' + n; for(let c of strN) if(c == '7') cnt ++ console.log('Number of 7\'s in number: ' + cnt)

about 4 years ago · Juan Pablo Isaza Report

0

Siguiendo su enfoque, necesita almacenar el último dígito en una variable diferente y usarlo para verificar si es un 7

 var a = 709728457; var b = []; var n = 0; while (a) { const lastDigit = a % 10; b.push(lastDigit); // if you still need to store all digits a = Math.floor(a / 10); if (lastDigit == 7) { n = n + 1; } } console.log("number of 7's:" + n);

about 4 years ago · Juan Pablo Isaza Report

0

var a = 7686774737 var no = String(a).split('').filter(e=>e==7).length; console.log(no)
about 4 years ago · Juan Pablo Isaza 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!