Hi,
I’ve come across two challenges so far on JS Hero that i cant complete.
Some of them dont have a solution so Im looking for help.
the first one is:
Exercise
Write a function flat
that flattens a two-dimensional array with 3 entries.
Example: flat(loshu)
should return [4, 9, 2, 3, 5, 7, 8, 1, 6]
. Thereby loshu
is the magic square from the example above.
My Code:
I’ve put is JS console, and it works, so i cant see why it is wrong…
function flat (array){
let array1 = array[0];
let array2 = array[1];
let array3 = array[3];
let array4 = array1.concat(array2);
let array5 = array4.concat(array3);
return array5;
}
ANS:
Reading your code successfully.
flat
is a function.
flat
has 1 parameter(s).
flat([[], [], []])
does not return []
, but [ undefined ]
.
Test-Error! Correct the error and re-run the tests!
The second one is
Exercise
Write a function xor
that takes two Boolean values. If both values are different, the result should be true
. If both values are the same, the result should be false
.
I.e.: The calls xor(true, false)
and xor(false, true)
should return true
. The calls xor(true, true)
and xor(false, false)
should return false
.
function xor ( a,b ) {
let or = a && !b
return or;
}
ANS:
Reading your code successfully.
xor
is a function.
xor
has 2 parameter(s).
xor(true, true)
returns false
.
xor(false, false)
returns false
.
xor(true, false)
returns true
.
xor(false, true)
does not return true
, but false
.
Test-Error! Correct the error and re-run the tests!
Thanks !!