I need to write a function, that accepts two arguments (numbers), for example a and b. I need to write a loop that prints all numbers from 0 to a that can be divided by b.
This is what I have so far:
function myFunction(a, b) {
let number = 0;
for(var i = 1; i <= a; i += 1) {
number = i;
}
//so far, I am just printing all the numbers from 0 to 10
}
myFunction(10, 3);
Hello! so I was trying to break the code into smaller bits, and here is what I am starting with:
function myFunction(a, n) {
for (let i = 0; i <= a; i++) {
let results = i / n;
console.log(results);
}
}
myFunction(10, 3);
Basically I want to loop through, but I am missing a step, as I am trying to get atleast the 0, 1.333,2.666, 3 as the result. Can you advise what am I missing?
WOW! That worked. This is amazing! Let me show you my current code.
function displayEvenlyDivisibleNumbers(a, b) {
for (let number = 0; number <= a; number++) {
if (!(number % b)) {
console.log(number);
}
}
}
displayEvenlyDivisibleNumbers(10, 3);
I am quite new to Javascript, but decided to learn it a bit differently. I want to find useful practice example, such as this one and try to solve it on paper and then find how to turn it to code.
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.