-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray-practice.html
42 lines (37 loc) · 1.1 KB
/
array-practice.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Array Warm Up</title>
</head>
<body>
<script>
"use strict";
// TODO: Create a function below, concatFirstAndLast, that takes in an array and returns the first and last inputs
// concatentated together if both elements are strings. If either the first or last element does is not a string
// or if the array contains one or fewer elements, return false.
//
// Example input/output...
//
// concatFirstAndLast(['a', 'b', 'c']) // 'ac'
// concatFirstAndLast([]) // false
// concatFirstAndLast(['23', '12', 'hello']) // '23hello'
// concatFirstAndLast([true]) // false
// concatFirstAndLast([true, 'bob']) // false
//
// */
//
let input1 = ['a','b','c']
function concatFirstAndLast(input1){
let firstElement = input1[0]
let lastElement = input1.reverse()[0]
if(typeof firstElement === "string" && typeof lastElement=== "string"){
return firstElement + lastElement
}else{
return false
}
}
concatFirstAndLast()
</script>
</body>
</html>