Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

214
Vistas
My code passes all my tests but some how edabit is not approving it
function bitwiseAND(n1, n2) {
  let a = n1.toString(2).padStart(8, "0");
  let b = n2.toString(2).padStart(8, "0");
  let x = "";
  for (let i = 0; i < 8; i++) {
     if (+a[i] === 1 && +a[i] === +b[i]) x = x + "1";
     else x = x + "0";
}
return +x
}

function bitwiseOR(n1, n2) {
  let a = n1.toString(2).padStart(8, "0");
  let b = n2.toString(2).padStart(8, "0");
  let x = "";
  for (let i = 0; i < 8; i++) {
    if (+a[i] === 1 || +b[i] === 1) x = x + "1";
    else x = x + "0";
}
return +x
}

function bitwiseXOR(n1, n2) {
  let a = n1.toString(2).padStart(8, "0");
  let b = n2.toString(2).padStart(8, "0");
  let x = "";
  for (let i = 0; i < 8; i++) {
    if ((+a[i] === 1 && +b[i] === 0) || (+a[i] === 0 && +b[i] === 1))
      x = x + "1";
    else x = x + "0";
}
return +x
}

This is link to the challenge

challenge was to Write three functions to calculate the bitwise AND, bitwise OR and bitwise XOR of two numbers.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your code is good, the only thing that is missing is to convert the binary to an integer on your return values.

Insted of

return +x

Try

return parseInt(x, 2)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda