Smallest Common Multiple Code

Tell us what’s happening:

Your code so far

function smallestCommons(arr) {
  var arr1 = [];
  var arr2 = [];
  var count = arr[0];
  for(var i=1; i<100;i++) {
  for(var s=0; s<arr1.length;s++) {
    for(var t=arr[0]; t<=arr[1];t++) {
      if(arr1[s] % t ==0) {
    if(count>=arr[1]) {
      return arr[s];
    } else {
  return count;

**Your browser information:**

Your Browser User Agent is: ```Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0```.

**Link to the challenge:**

Do you have a question?

I can’t get the code to work and I was wandering where I went wrong

It’s returning undefined. Although it should return a number

In your code, you have the following if statement:

if(count>=arr[1]) {

In the test case of smallestCommons([1,5]), arr[1] is 5, so when count >= 5, you return arr[s]. The problem is when count is equal to 5, s is equal to 11 and arr[11] results in undefined, because there are only 2 elements (and not 12 elements) in arr.

I suggest you put a few more console.log statements to see what the values of each variable are at various points in your solution, to help you figure out your logic error.