# A Rule of Divisibility by 13

Here is the [Kata] for reference (https://www.codewars.com/kata/564057bc348c7200bd0000ff/train/javascript)

I have no Idea why it wont accept my function. its saying

This is my code, it works elsewhere

``````function thirt(n)
{
var array = n.split('')
console.log(array)
var arrayReverse=array.reverse()
console.log(arrayReverse)
var arrayTimes = []
var arrayremainders = [1, 10, 9, 12, 3, 4]
for(x=0;x<n.length;x++)
{
var sequence

if(x%6===0)
{
sequence = 0
}
else
{
sequence = x%6
}

console.log(arrayReverse[x]+' X '+arrayremainders
[sequence])
console.log('arrayReverse'+' X '+'arrayremainders')

arrayTimes.push(arrayReverse[x]*arrayremainders[sequence])

}

console.log(arrayTimes)

{
}

}

``````

At some point, your function is receiving a value that is not a string.

Ok I need a way of repeatedly calling this function until n (>=0) â€śx is greater than or = 0â€ť I think thats what it wants

so I have the way to do it once

``````function thirt(n)
{
var static = n
var arrayremainders = [1, 10, 9, 12, 3, 4]

function arrayTimes(array)
{
var array = n.split('')
console.log(array)
var arrayReverse=array.reverse()
console.log(arrayReverse)
var arrayTimes = []
for(x=0;x<n.length;x++)
{
var sequence

if(x%6===0)
{
sequence = 0
}
else
{
sequence = x%6
}

console.log(arrayReverse[x]+' X '+arrayremainders
[sequence])
console.log('arrayReverse'+' X '+'arrayremainders')

arrayTimes.push(arrayReverse[x]*arrayremainders[sequence])

}

console.log(arrayTimes)

{
}
console.log(static)

}

arrayTimes(n)

}

thirt("1234567")

``````

Ok this is pissing me off but I am pretty sure this works

for all of their basic tests except for 987654321 which should be 303 not 30 I think

``````
Test.it("Basic tests",function() {
Test.assertEquals(thirt(8529), 79)
Test.assertEquals(thirt(85299258), 31)
Test.assertEquals(thirt(5634), 57)
Test.assertEquals(thirt(1111111111), 71)
Test.assertEquals(thirt(987654321), 30)
})})

``````

Im still getting that n.split error which I dont understand, it works on the compiler im using

``````
function thirt(n)
{

var static = String(n)
var arrayremainders = [1, 10, 9, 12, 3, 4]

function arrayTimes(array)
{
var array = n.split('')
console.log(array)
var arrayReverse=array.reverse()
console.log(arrayReverse)
var arrayTimes = []
for(x=0;x<n.length;x++)
{
var sequence

if(x%6===0)
{
sequence = 0
}
else
{
sequence = x%6
}

console.log(arrayReverse[x]+' X '+arrayremainders
[sequence])
console.log('arrayReverse'+' X '+'arrayremainders')

arrayTimes.push(arrayReverse[x]*arrayremainders[sequence])

}

console.log(arrayTimes)

{
}
console.log(static)

}

if(arrayTimes(static)===static)
{
return static
}

else
{
arrayTimes(static)
}

}

``````

`split()` is a string method. It looks like your `thirt` function is expected to take an integer. You cannot `split` an integer.

I considered this so I added static = String(n)

shouldnt this ensure that its a string before I tried to split it so there shouldnt be an issue

But you arenâ€™t splitting `static`. Youâ€™re splitting `n`, which is still an integer.

First sum = 1x1 + 2x10 +3x9 + 4x12 + 5x3 + 6x4 + 7x1 + 8x10 + 9x9 = 1 + 20 + 27 + 48 + 15 +24 + 7 + 80 + 81 = 303

Second sum = 3x1 + 0x10 + 3x9 = 3 + 0 + 27 = 30

Third sum = 0x1 + 3x10 = 0 + 30 = 30

So 30 is the correct answer.

1 Like

oh balls just noticed im still calling it on the n lol thanks