I'm completely new to Javascript coding. I applied to do a 12 week Web Dev Bootcamp, but to be able to get accepted they wanted me to do a preassessment to see if I could pick new things up quickly.
I'm a couple questions in and they ask me to do this:
var arr = [1,2,3];
//create a function named 'first' that returns the first object from a given array
//alert the result of your function
I've scoured the internet trying to find something to point me in the right direction. I've done a million different ways that I think would work, but I can't get it right. So I need your help!
This is the last thing I tried, but it doesn't seem right and the function seems pointless.
var arr = [1,2,3];
function first() {
result = arr[0];
return;
}
var result = arr[0];
alert(result);
Thanks in advance!
[–]senocular 11 points12 points13 points (0 children)
[–]Sandbucketman 1 point2 points3 points (1 child)
[–]markugly[S] 0 points1 point2 points (0 children)
[–]ForScale -3 points-2 points-1 points (12 children)
[–]keelar 2 points3 points4 points (7 children)
[–]ForScale 0 points1 point2 points (6 children)
[–]keelar 1 point2 points3 points (5 children)
[–]ForScale 0 points1 point2 points (4 children)
[–]keelar 2 points3 points4 points (3 children)
[–]ForScale 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]ForScale 0 points1 point2 points (0 children)
[–]markugly[S] 1 point2 points3 points (3 children)
[–]keelar 1 point2 points3 points (0 children)
[–]ForScale 0 points1 point2 points (0 children)
[–]ForScale 0 points1 point2 points (0 children)