Help Solving Two Javascript Issues

Asked

Viewed 111 times

0

Hello, I’m not able to solve these two issues, could help me.

function dobroDoNumero (){
  var dobroA = 4+4;
  var dobroB = 7+7;
  var dobroC = 8+-8;
  var resultado = dobroA+ ', ' +dobroB+ ', ' +dobroC
  return resultado
}
function metade(){
  var num1 = 4/2;
  var num2 = 60/2;
  var num3 = 30/2;
  var resultado = num1+ ', ' +num2+ ', ' +num3;
  return resultado
  console.log(resultado)
}

Thank you :)

  • What’s the problem with the first code?

  • Avoid cossole.log after Return: function metade(){
 var num1 = 4/2;
 var num2 = 60/2;
 var num3 = 30/2;
 var resultado = num1+ ', ' +num2+ ', ' +num3; console.log(resultado)

 return resultado
 }

  • Explain better what is the problem with the codes

1 answer

1

Hello.

In the first code there is an error that is showing on the console: 8,14,0.

The error is in the fourth line: var dobroC = 8+-8;

Solution:

function dobroDoNumero(){
  var dobroA = 4*2;
  var dobroB = 7*2;
  var dobroC = 8*2;
  var resultado = dobroA+ ', ' +dobroB+ ', ' +dobroC;
  return resultado;
}
console.log(dobroDoNumero());
// 8, 14, 16

In the second code, console.log(resultado) after the call from return resultado;.

Solution:

function metade(){
  var num1 = 4/2;
  var num2 = 60/2;
  var num3 = 30/2;
  var resultado = num1+ ', ' +num2+ ', ' +num3;
  console.log(resultado);
// 2, 30, 15
  return resultado;
}
metade()

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.