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

161
Views
Cómo intercambiar el primer y el último dígito de un número usando for loop en Javascript

Necesito pedirle al usuario que ingrese un número de 3 dígitos y luego intercambie el primer y el último número usando un bucle for. Esto es lo que tengo hasta ahora, pero estoy atascado. Usar un bucle for parece ilógico, pero eso es lo que tengo que hacer:

 num = prompt("Please input a number with 3 digits."); let firstDigit = num[0]; let secondDigit = num[1]; let lastDigit = num[2]; for (firstDigit < 10; secondDigit < 10; lastDigit < 10); { console.log(lastDigit + secondDigit + firstDigit); }

¡Por favor ayuda!

Gracias

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

0

¿es de ayuda para ti?

 // let num = prompt("Please input a number with 3 digits."); // if (num.length > 3) alert("3 digits please"); // else { // let answer = ""; // for (var i = 2; i >= 0; i--) { // answer = answer + num[i]; // } // console.log(answer); //} let num = prompt("Please input a number"); let temp = ""; let answer = ""; for(let i = 0 ; i < num.length; i++) { if (i === 0) temp = num[i]; // save first number to temp else if (i === num.length - 1) { // When the last number is encountered, the last number is put at the beginning, and the first number stored in temp is put at the end. answer = answer + temp; answer = num[i] + answer; } else answer = answer + num[i]; } console.log(answer);

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!