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

88
Views
This Javascript program has nothing in the console

so i need an answer to this

i was expecting to have the console look like this (if you input 69)

 69
 208
 104
 52
 26
 13
 40
 20
 10
 5
 16
 8
 4
 2
 1

but it has nothing in the console so here is the program code

function mod(n, m) {
  return ((n % m) + m) % m;
}
var a = prompt("please input a number");
do {
  var b = mod(a, 2)
  if (b == 0) {
    var a = a / 2
  } else a = (3 * a) + 1
  console.log("a");
}
while (a !== 0)

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

0

There are several mistakes in this code.

First of all, you should write console.log(a) to log the a variable.

Also, you do not have to declare a variable again.

Lastly, your code is on an infinite loop because a doesn't match a !== 0 in the loop.

I believe this is the code you want.

function mod(n, m) {
  return ((n % m) + m) % m;
}
let a = prompt("please input a number");
let b;
do {
  b = mod(a, 2)
  if (b == 0) {
    a = a / 2
  } else {
    a = (3 * a) + 1
  }
  console.log(a);
}
while (a !== 1)
about 4 years ago · Juan Pablo Isaza Report

0

You can try this:

function mod(n, m) {
  return ((n % m) + m) % m;
}
var a = prompt("please input a number");
do {
  var b = mod(a, 2)
  if (b == 0) {
    var a = a / 2
  } else a = (3 * a) + 1
  console.log(a);
}
while (a !== 1)

And if you want to display your input as well, try:

function mod(n, m) {
  return ((n % m) + m) % m;
}
var a = prompt("please input a number");
var c= a;
console.log(c);
do {
  var b = mod(a, 2)
  if (b == 0) {
    var a = a / 2
  } else a = (3 * a) + 1
  console.log(a);
}
while (a !== 1)

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!