Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
javascript-demo
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
Deep Bhuller
javascript-demo
Commits
d598a3f4
Commit
d598a3f4
authored
Apr 09, 2021
by
dbhuller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added examples for switch and while/do-while loops
parent
6f12efb0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
8 deletions
+77
-8
basic.html
basic.html
+15
-0
external-js.js
external-js.js
+62
-8
No files found.
basic.html
View file @
d598a3f4
...
...
@@ -87,6 +87,21 @@
document
.
write
(
"<br>"
)
arrForOf
(
myArr
);
</script>
<h1>
Switch Statement
</h1>
<script>
switchExample
(
0
);
switchExample
(
1
);
switchExample
(
2
);
switchExample
(
3
);
switchExample
(
4
);
</script>
<h1>
While/Do-While Loop
</h1>
<script>
document
.
write
(
"While Loop:<br> "
);
whileExample
();
document
.
write
(
"Do-While loop: "
)
doWhileExample
();
</script>
</body>
</html>
\ No newline at end of file
external-js.js
View file @
d598a3f4
...
...
@@ -38,7 +38,7 @@ function add(a, b) {
function
conditionalDemo
(
arg
)
{
let
myArg
=
"Deep"
;
if
(
arg
==
myArg
)
{
if
(
arg
==
myArg
)
{
document
.
write
(
"You entered the same arg. Entered: "
+
arg
+
", "
+
" Expected: "
+
myArg
);
}
else
{
document
.
write
(
"You didnt enter the same arg. Entered: "
+
arg
+
", "
+
" Expected: "
+
myArg
);
...
...
@@ -47,14 +47,68 @@ function conditionalDemo(arg) {
function
arrForIn
(
arr
)
{
document
.
write
(
"With for-in: "
);
for
(
let
val
in
arr
)
{
for
(
let
val
in
arr
)
{
document
.
write
(
val
);
}
}
function
arrForOf
(
arr
)
{
document
.
write
(
"With for-of: "
)
for
(
let
val
of
arr
)
{
for
(
let
val
of
arr
)
{
document
.
write
(
val
);
}
}
function
switchExample
(
switchVal
)
{
switch
(
switchVal
)
{
case
0
:
document
.
write
(
"zero<br>"
);
break
;
case
1
:
document
.
write
(
'one<br>'
);
break
;
case
2
:
document
.
write
(
'two<br>'
);
break
;
case
3
:
document
.
write
(
'three<br>'
);
break
;
case
4
:
document
.
write
(
'four<br>'
);
break
;
case
5
:
document
.
write
(
'five<br>'
);
break
;
case
6
:
document
.
write
(
'six<br>'
);
break
;
case
7
:
document
.
write
(
'seven<br>'
);
break
;
case
8
:
document
.
write
(
'eight<br>'
);
break
;
case
9
:
document
.
write
(
'nine<br>'
);
break
;
}
}
function
whileExample
()
{
let
x
=
0
;
while
(
x
<
10
)
{
document
.
write
(
x
+
"<br>"
);
x
++
;
}
}
function
doWhileExample
()
{
let
result
=
''
;
let
i
=
0
;
do
{
i
=
i
+
1
;
result
=
result
+
i
;
}
while
(
i
<
5
);
document
.
write
(
result
);
}
\ No newline at end of file
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