Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
javascriptAssignment
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
Julius Wu
javascriptAssignment
Commits
2d8dabb5
Commit
2d8dabb5
authored
Apr 09, 2021
by
Julius Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
complete assignment
parents
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
134 additions
and
0 deletions
+134
-0
javascriptBasicAssiginment.js
javascriptBasicAssiginment.js
+134
-0
No files found.
javascriptBasicAssiginment.js
0 → 100644
View file @
2d8dabb5
//Basic JavaScript Examples
// Variables - Scopes
var
global
=
"-global"
function
variablesScopesExample
()
{
var
local
=
"-local"
console
.
log
(
"this is local in the function "
+
local
);
console
.
log
(
"this is global in the function "
+
global
);
}
console
.
log
(
"this is global in the main "
+
global
);
variablesScopesExample
();
//this is global in the main -global
//this is local in the function -local
//this is global in the function -global
// Functions
function
noParm
(){
return
(
"hello world"
)
}
noParm
();
//hello world
function
withParms
(
n1
,
n2
){
return
n1
+
n2
;
}
withParms
(
1
,
2
);
//3
function
withParms2
(
name
,
companyname
){
return
(
"My name is "
+
name
+
" "
+
"I work for "
+
companyname
);
}
withParms2
(
"Julius"
,
"Nisum"
);
//My name is julius I work for Nisum
withParms2
(
"Julius"
);
//My name is julius I work for undefined
withParms2
();
//My name is undefined I work for undefined
// Operators
let
a
=
10
;
console
.
log
(
a
)
let
pre
=
++
a
;
console
.
log
(
a
);
//11
console
.
log
(
pre
);
//11
let
after
=
a
++
;
console
.
log
(
a
);
//12
console
.
log
(
after
);
// 11
let
c
=
2
;
let
d
=
'hello'
;
console
.
log
(
c
+=
3
);
//5
console
.
log
(
d
+=
' world'
);
// hello world
console
.
log
(
true
||
false
);
// true
console
.
log
(
false
||
true
);
// true
console
.
log
(
true
||
true
);
// true
console
.
log
(
false
||
false
);
// false
console
.
log
(
false
&&
false
);
// false
console
.
log
(
true
&&
false
);
// false
console
.
log
(
false
&&
true
);
// false
console
.
log
(
true
&&
true
);
// true
// Conditional statements
function
evenOrOdd
(
num
){
if
(
num
%
2
===
0
){
console
.
log
(
"even"
);
}
else
{
console
.
log
(
"odd"
);
}
}
evenOrOdd
(
1
)
//odd
evenOrOdd
(
2
)
//even
switch
(
new
Date
().
getDay
())
{
case
0
:
day
=
"Sunday"
;
break
;
case
1
:
day
=
"Monday"
;
break
;
case
2
:
day
=
"Tuesday"
;
break
;
case
3
:
day
=
"Wednesday"
;
break
;
case
4
:
day
=
"Thursday"
;
break
;
case
5
:
day
=
"Friday"
;
break
;
case
6
:
day
=
"Saturday"
;
};
//Friday (as of April 9, 2021)
// Loops
let
arr
=
[
"a"
,
"b"
,
"c"
];
for
(
ele
in
arr
)
{
console
.
log
(
ele
)}
// 0,1,2
for
(
ele
in
arr
)
{
console
.
log
(
ele
)}
// a,b,c
for
(
let
i
=
0
;
i
<
arr
.
length
;
i
++
){
console
.
log
(
i
);
console
.
log
(
arr
[
i
]);
}
// 0 , a , 1 , b , 2 , c
let
i
=
0
;
while
(
i
<
arr
.
length
){
console
.
log
(
i
);
console
.
log
(
arr
[
i
]);
i
++
;
}
// 0 , a , 1 , b , 2 , c
let
result
=
''
let
i
=
0
;
do
{
i
=
i
+
1
;
result
=
result
+
i
;
}
while
(
i
<
5
);
// "12345"
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