FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
javascript-basic-assessment/assessment.js at master · yabbbs/javascript-basic-assessment · GitHub
yabbbs
/
javascript-basic-assessment
Public
forked from
DevMountain/javascript-basic-assessment
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
javascript-basic-assessment
/
assessment.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
223 lines (161 loc) · 5.65 KB
Breadcrumbs
javascript-basic-assessment
/
assessment.js
Copy path
File metadata and controls
223 lines (161 loc) · 5.65 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// #1 Create a variable called hello and assign it the string 'goodbye'
let
hello
=
'goodbye'
// #2 Use the variable iLove to create a new variable called iLoveCode that is assigned the string "I love code"
var
iLove
=
'I love'
;
var
iLoveCode
=
(
iLove
+
' code'
)
// #3 Make an object called bob and give it the following properties
// bob has a height of 6ft (string)
// bob has an age of 24 (Number)
// bob has hair, that has style spikey, and color brown (object)
// bob is not presidentOfTheUnitedStates (boolean)
// bob likes apples, bananas, and cherries (array of strings)
var
bob
=
{
height
:
"6ft"
,
age
:
24
,
hair
:
{
style
:
'spikey'
,
color
:
'brown'
}
,
presidentOfTheUnitedStates
:
false
,
likes
:
[
'apples'
,
'bananas'
,
'cherries'
]
}
// #4 Change my shirt color to pink using dot notation
var
myShirt
=
{
type
:
'polo'
,
color
:
'red'
}
;
myShirt
.
color
=
'pink'
// Change my shirt type to spandex using square bracket notation
var
myOtherShirt
=
{
type
:
'polo'
,
color
:
'red'
}
;
myOtherShirt
.
type
=
'spandex'
//
// // #5 Create an object that tracks a count of animals in a zoo. Call it 'zoo'
// // The key should be the animal name(string) and the value should be how many there are.
// // Our zoo has 8 monkeys, 4 giraffes and 2 elephants
//
let
zoo
=
{
monkeys
:
8
,
giraffes
:
4
,
elephants
:
2
}
//
//
//
// // #6 Loop through this object and change all keys that start with the letter s to have a value of 's'
var
snake
=
{
sliters
:
'sideways'
,
eats
:
'rodents'
,
says
:
'ssss'
,
smells
:
'heat'
,
runs
:
'legless'
}
;
for
(
let
key
in
snake
)
{
if
(
key
[
0
]
===
's'
)
{
snake
[
key
]
=
's'
}
}
//#7 Create an array of strings that are the 7 primary colors in the rainbow - red, orange, yellow, green, blue,
// indigo, violet (lower-case). Call your array rainbowColors
var
rainbowColors
=
[
'red'
,
'orange'
,
'yellow'
,
'green'
,
'blue'
,
'indigo'
,
'violet'
]
// #8 Using this array do the following
var
heroes
=
[
'superman'
,
'batman'
,
'flash'
]
;
// add 'wonderwoman' to the end
heroes
.
push
(
'wonderwoman'
)
// remove 'superman' and store him in a variable called firstHero
var
firstHero
=
heroes
.
shift
(
)
;
// add 'spongebob' to the start of the array
heroes
.
unshift
(
'spongebob'
)
// remove 'flash' from the array and store him in a variable called secondHero
// leave batman in the array but put a copy of him on a variable called thirdHero
var
thirdHero
=
heroes
[
1
]
// #9 Write a function called addItem that takes in an array and an item, adds the item to
// the array, and returns the array with the added item.
function
addItem
(
arr
,
item
)
{
arr
.
push
(
item
)
;
return
arr
;
}
// #10 Write a function called removeItem that takes in an array of strings, and a string.
// Removes all instances of that string from the array. And return the modified array.
// The order of the array should not be changed
function
removeItem
(
arr
,
str
)
{
let
newArr
=
arr
.
filter
(
(
element
)
=>
element
!==
str
)
return
newArr
}
// removeItem(arr, "three")
// var arr = ["spray", "limit", "elite", "exuberant", "destruction", "present"];
// var longWords = words.filter(function(word){
// return word.length > 6;
// });
// #11 Write a function called doubleTheFun that takes 1 parameter. It should double numbers, and
// repeats strings. example 4->8, 2.5->5, 'Awesome'->'AwesomeAwesome'
function
doubleTheFun
(
yup
)
{
if
(
Number
(
yup
)
)
{
return
yup
*
2
}
else
{
return
yup
+
yup
}
}
// #12 Write function getValueOfProperty that takes in an object, and the name of a property on the object
// return the value from the object that corresponds to the property
function
getValueOfProperty
(
obj
,
name
)
{
return
obj
[
name
]
}
// #13 Write a function called makeChatMessage that takes in a message and author as parameters
// and returns an object with a message, author, and timestamp, that is
// the current time as a Date object
function
makeChatMessage
(
mes
,
auth
)
{
return
{
message
:
mes
,
author
:
auth
,
timestamp
:
new
Date
(
)
}
}
// #14 Create a function called coderTest that takes in an object that is a person. It looks to see if the person’s
// name is Jeremy and then changes the person object to have a property called lovesCode with a value of 10. If their
// name is Brack set lovesCode to 0. otherwise set lovesCode to 5.
function
coderTest
(
person
)
{
if
(
person
.
name
===
'Jeremy'
)
{
person
.
lovesCode
=
10
;
}
else
if
(
person
.
name
===
"Brack"
)
{
person
.
lovesCode
=
0
;
}
else
person
.
lovesCode
=
5
;
}
// #15 Create a function called outside that takes in a temperature (number), a humidity(number), and a cloudiness(number),
// in that order. Using the following to return the correct values
/*
temperature over 80 and humidity over 40 - return "I'm all sweat"
temperature under 40 and cloudiness over 60 - return "I have icecicles"
temperature over 80 and humidity under 40 and cloudiness under 20 - return "I'm literally in the desert"
temperature over 80 or humidity over 50 or cloudiness over 50 - return "Hmm, probably not"
Otherwise - return "I love outside"
*/
function
outside
(
temp
,
humid
,
cloud
)
{
if
(
temp
>
80
&&
humid
<
40
&&
cloud
<
20
)
{
return
"I'm literally in the desert"
}
else
if
(
temp
>
80
&&
humid
>
40
)
{
return
"I'm all sweat"
}
else
if
(
temp
<
40
&&
cloud
>
60
)
{
return
"I have icecicles"
}
if
(
temp
>
80
)
{
return
"Hmm, probably not"
}
else
if
(
humid
>
50
)
{
return
"Hmm, probably not"
}
else
if
(
cloud
>
50
)
{
return
"Hmm, probably not"
}
else
return
"I love outside"
}
// #16 Create a function called callerBack that takes in a function (holla) and a string parameter(back) and
// invokes it(holla) passing in "back + " back""
// example - If I call you with 'Give it' you should invoke holla with 'Give it back'
function
callerBack
(
holla
,
back
)
{
return
holla
(
back
+
' back'
)
}
Back
|
FazBrowse Home
|
New Git URL