Help validate results separately Javascript

Asked

Viewed 93 times

-3

Hello, I have this question to solve, I make the formula to find the highest value of the two numbers, but I’m having difficulty validating the results in each question. I took a print to show. The values are presented all together and not separately so that each question validates them. Can help me?

function eMaior (numeros){
  return Math.max (10,9)+ ", " +(5,11)+ ", " +(4,4)+ ", " +(2,120);
 }

Thank you :)inserir a descrição da imagem aqui

2 answers

1

Hello.

In the question itself is saying that it has two parameters in the function eMaior.

Then do it:

function eMaior (numA,numB){
  return Math.max(numA,numB);
}
var test = (eMaior(10,9) == 10);
// eMaior retorna 10
var test2 = (eMaior(5,11) == 11);
// eMaior retorna 11
console.log(test);
// retorna true
console.log(test2);
// retorna true
  • nesata in the case - Function dobroDoProximo(numero){ var result = [6, 1, -3]; Return result *2 } does not recognize why? Ps. Thank you :)

  • Because the resultado is an array and not a number.

  • In case to return a valid and separate value for each question should be like this 
function dobroDoProximo(numero){
 var somaA = 6+6;
 var somaB = 1+1;
 var somaC = -3+-3;
 var resultado = [somaA, somaB, somaC];
 return resultado
}


  • Yes. That’s right

1

An even more direct approach to this problem would be to create a reference to the method Math.max, since the function eMaior will return the same result.

var eMaior = Math.max

Working:

var eMaior = Math.max;

console.log('Maior número entre 10 e 9: ' + eMaior(10, 9));
console.log('Maior número entre 5 e 11: ' + eMaior(5, 11));

Browser other questions tagged

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