-3
The objective of this exercise is to return if the input number is divisible by x
or not.
Your program will always receive input: an integer number and an integer number representing x
and should print on the screen if the first entry number is divisible by x
.
The input will always be two integer numbers.
The output should always be true or false.
Sample Input 0
10 2
Sample Output 0
true
Explanation 0
10 is divided by 2 because by dividing 10 by 2 the rest is 0.
That’s the code I’m using:
function solucao(numero, x) {
// seu código aqui
return numero % x == 0; {
console.log(solucao (10,2))
if (resto == 0) {
console.log("true");
} else {
console.log("false");
}
}
}
and what is the difficulty? put in question the code you have done so far and where you have difficulty
– Ricardo Pontual
So, I’m lost in the question, how would I code in and such
– Leônidas Neto
if you don’t know where to start best to go back to the basics. Here in the OS we do not give this help, we can help you with a specific problem but we will not do the code for you, because then you will not learn :) search on the site that will probably find question about all the basics of javascript, how to read information, validate, etc
– Ricardo Pontual
the code I was trying to
– Leônidas Neto
Function solucao(numero, x) { const resto = numero % 2; if (resto == 0) { console.log("true") } } solved(10);
– Leônidas Neto
but it’s wrong, and I’m half lost! Trying to learn only, but here’s the thing
– Leônidas Neto
now ta best Leonidas, click here to edit your question and add that code there
– Ricardo Pontual
I edited, could you give me some hint?
– Leônidas Neto
You’re seeing if the number is divisible by 2, not by
x
, then it should befunction solucao(numero, x) { return numero % x == 0; }
and to call,console.log(solucao(10, 2))
(to see if 10 is divided by 2),console.log(solucao(90, 3))
(to see if 90 is divisible by 3), etc - oh yes, I also made the function returntrue
orfalse
, instead of printing the value (and you only print if it’s true, but what if it’s not? ) - because then whoever called the function only takes the result (true or false) and decides what to do with it (can even print a message, if applicable)– hkotsubo
Stackoverflow increases the mutual help of software developers. Your question doesn’t seem useful to me, or to most of the Stackoverflow community. Even if I gave you the answer, you wouldn’t understand why I’m telling you. You have the function poorly implemented and poorly called... I suggest you take a basic course at Khan Academy, for example, or even see some tutorials on Youtube. Don’t give up, it’s about wanting to learn!
– Daniel Pinto