Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
javascript-exercise
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shanelle Valencia
javascript-exercise
Commits
f0078c69
Commit
f0078c69
authored
Apr 09, 2021
by
Shanelle Valencia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean thy code
parent
d0d10637
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
34 deletions
+55
-34
buttonFunc.js
buttonFunc.js
+0
-1
loops.js
loops.js
+13
-5
practice.html
practice.html
+17
-28
randomMood.js
randomMood.js
+25
-0
No files found.
buttonFunc.js
View file @
f0078c69
function
testButton
()
{
document
.
write
(
"Why did you click me?"
);
}
loops.js
View file @
f0078c69
...
...
@@ -52,20 +52,28 @@ function whileLoop() {
function
switchStatements
(
arr
)
{
const
randomNum
=
arr
[
Math
.
floor
(
arr
.
length
*
Math
.
random
())];
let
response
=
''
;
switch
(
randomNum
)
{
case
"exercise"
:
return
(
`
${
randomNum
}
: Yikes`
);
response
=
(
`
${
randomNum
}
: Yikes`
);
break
;
case
"sleep"
:
return
(
`
${
randomNum
}
: yes please`
);
response
=
(
`
${
randomNum
}
: yes please`
);
break
;
case
"code"
:
return
(
`
${
randomNum
}
: breathe code 24/7`
);
response
=
(
`
${
randomNum
}
: breathe code 24/7`
);
break
;
case
"eat"
:
return
(
`
${
randomNum
}
: all day`
);
response
=
(
`
${
randomNum
}
: all day`
);
break
;
default
:
re
turn
(
`
${
randomNum
}
: error`
);
re
sponse
=
(
`
${
randomNum
}
: error`
);
}
// document.write(response);
return
response
;
}
...
...
practice.html
View file @
f0078c69
<html>
<meta
charset=
"UTF-8"
>
<head>
<title>
My First Program
</title>
<script
language =
"javascript"
type =
"text/javascript"
>
...
...
@@ -9,23 +10,9 @@
document
.
write
(
localVar
);
}
</script>
<script
language =
"javascript"
type =
"text/javascript"
>
function
moodRandomizer
()
{
const
moods
=
[
"happy 😊"
,
"sad 😢"
,
"sleepy 🥱"
,
"hangry 😡"
,
"cool 😎"
,
"lost 🤯"
,
"Friday vibez"
]
const
randomIdx
=
Math
.
floor
(
moods
.
length
*
Math
.
random
())
return
moods
[
randomIdx
];
};
function
todaysMood
(
name
)
{
myMood
=
moodRandomizer
();
document
.
write
(
`
${
name
}
is feeling
${
myMood
}
today.`
);
if
(
myMood
===
"Friday vibez"
)
{
alert
(
"FRIDAY MOOD: 🕺🏻🕺🏻🕺🏻"
);
}
}
</script>
<script
type=
"text/javascript"
src=
"randomMood.js"
></script>
<script
type=
"text/javascript"
src=
"buttonFunc.js"
></script>
<script
type=
"text/javascript"
src=
"loops.js"
>
const
arr
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
];
...
...
@@ -45,29 +32,31 @@
</marquee>
</h2>
<
script
>
document
.
write
(
globalVar
);
<
!-- test local vs global vars --
>
<!-- <script>
document.write("<br>");
variableScopes();
document.write(localVar); //ref error due to scope - will not render
</script>
</script>
-->
<
h3
>
<
script>
todaysMood
(
"Shanel"
);
</script
>
<
form
action=
""
>
<
input
id=
"typeYourName"
placeholder=
"type your name"
>
<input
type=
"button"
onclick=
"todaysMood()"
value=
"Random Mood"
>
</form
>
</h3>
<script>
document
.
write
(
doWhileLoop
(
arr
)
+
'<br>'
+
switchStatements
(
strArr
)
);
document
.
write
(
doWhileLoop
(
arr
)
+
'<br>'
);
</script>
<br>
<input
type=
"button"
onclick=
"testButton()"
value=
"Click Me"
>
<input
type=
"button"
onclick=
"testButton()"
value=
"Click?"
>
<input
type=
"button"
onclick=
"document.write(switchStatements(strArr))"
value=
"Task"
>
</body>
</html>
\ No newline at end of file
</html>
randomMood.js
0 → 100644
View file @
f0078c69
function
moodRandomizer
()
{
const
moods
=
[
"happy 😊"
,
"sad 😢"
,
"sleepy 🥱"
,
"hangry 😡"
,
"cool 😎"
,
"lost 🤯"
,
"Friday vibez"
]
const
randomIdx
=
Math
.
floor
(
moods
.
length
*
Math
.
random
())
return
moods
[
randomIdx
];
};
function
inputName
()
{
let
name
=
document
.
getElementById
(
"typeYourName"
).
value
;
return
name
;
}
function
todaysMood
()
{
let
myMood
=
moodRandomizer
();
let
name
=
inputName
();
document
.
write
(
`
${
name
}
is feeling
${
myMood
}
today.`
);
if
(
myMood
===
"Friday vibez"
)
{
alert
(
"FRIDAY MOOD: 🕺🏻🕺🏻🕺🏻"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment