FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
CCDATRCL/ProblemSet/Week 2/Problem/JavaScript/Stacks.js at main · flexycode/CCDATRCL · GitHub
flexycode
/
CCDATRCL
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
9
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
CCDATRCL
/
ProblemSet
/
Week 2
/
Problem
/
JavaScript
/
Stacks.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
46 lines (36 loc) · 1.4 KB
Breadcrumbs
CCDATRCL
/
ProblemSet
/
Week 2
/
Problem
/
JavaScript
/
Stacks.js
Copy path
File metadata and controls
46 lines (36 loc) · 1.4 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
let
stack
=
[
]
;
// Ask the user to enter the number of elements to push onto the stack
let
numElements
=
parseInt
(
prompt
(
"Enter the number of elements to push onto the stack: "
)
)
;
// Ask the user to enter the elements to push onto the stack
for
(
let
i
=
0
;
i
<
numElements
;
i
++
)
{
let
element
=
parseInt
(
prompt
(
`Element
${
i
+
1
}
: `
)
)
;
stack
.
push
(
element
)
;
}
// Print the stack elements
console
.
log
(
"Stack elements:"
)
;
console
.
log
(
stack
)
;
// Ask the user if they want to pop an element from the stack
let
input
=
prompt
(
"Do you want to pop an element from the stack? (yes/no): "
)
;
if
(
input
.
toLowerCase
(
)
===
"yes"
)
{
// Pop an element from the stack
let
poppedElement
=
stack
.
pop
(
)
;
// Print the popped element
console
.
log
(
"Popped element: "
+
poppedElement
)
;
// Print the updated stack elements
console
.
log
(
"Updated stack elements:"
)
;
console
.
log
(
stack
)
;
}
else
{
console
.
log
(
"No element popped from the stack."
)
;
}
// Ask the user if they want to push another element onto the stack
input
=
prompt
(
"Do you want to push another element onto the stack? (yes/no): "
)
;
if
(
input
.
toLowerCase
(
)
===
"yes"
)
{
// Ask the user to enter the new element
let
newElement
=
parseInt
(
prompt
(
"Enter the new element: "
)
)
;
stack
.
push
(
newElement
)
;
// Print the updated stack elements
console
.
log
(
"Updated stack elements:"
)
;
console
.
log
(
stack
)
;
}
else
{
console
.
log
(
"No new element pushed onto the stack."
)
;
}
Back
|
FazBrowse Home
|
New Git URL