Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dia004
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Joel Florentin
dia004
Commits
9c5a2d1d
Commit
9c5a2d1d
authored
Oct 21, 2021
by
Joel Florentin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
calculadora keydown
parent
2c607208
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
8 deletions
+30
-8
calculadora.html
+2
-2
main.css
+20
-0
main.js
+8
-6
No files found.
calculadora.html
View file @
9c5a2d1d
...
...
@@ -3,14 +3,14 @@
<head>
<meta
charset=
'utf-8'
>
<meta
http-equiv=
'X-UA-Compatible'
content=
'IE=edge'
>
<title>
Page Title
</title>
<title>
Calculadora
</title>
<meta
name=
'viewport'
content=
'width=device-width, initial-scale=1'
>
<link
rel=
'stylesheet'
type=
'text/css'
media=
'screen'
href=
'main.css'
>
</head>
<body>
<p
id=
"screen-anterior"
></p>
<input
type=
"text"
id=
"screen"
>
<input
type=
"text"
id=
"screen"
disabled
>
<table>
<tr>
<td
class=
"tecla"
>
7
</td>
<td
class=
"tecla"
>
8
</td>
<td
class=
"tecla"
>
9
</td>
<td
class=
"tecla"
>
+
</td>
...
...
main.css
0 → 100644
View file @
9c5a2d1d
#screen-anterior
,
#screen
{
width
:
11em
;
height
:
2em
;
margin-left
:
30%
;
text-align
:
right
;
}
.tecla
{
border
:
2px
solid
;
padding
:
3px
;
height
:
2em
;
width
:
2em
;
padding
:
0px
;
text-align
:
center
;
}
table
{
margin-left
:
30%
;
}
\ No newline at end of file
main.js
View file @
9c5a2d1d
const
teclas
=
document
.
querySelectorAll
(
'.tecla'
);
var
screen
=
document
.
getElementById
(
"screen"
);
var
screenAnterior
=
document
.
getElementById
(
"screen-anterior"
);
var
entrada_anterior
;
var
entrada_anterior
=
""
;
var
dot_posible
=
true
;
var
escribir
=
function
(
event
)
{
let
contenido
=
event
.
target
.
innerHTML
;
var
escribir
=
function
(
contenido
)
{
switch
(
getTipo
(
contenido
))
{
case
"num"
:
switch
(
getTipo
(
entrada_anterior
))
{
case
"num"
:
case
"num"
:
case
""
:
screen
.
value
=
Number
(
screen
.
value
+
contenido
)
break
;
case
"op"
:
...
...
@@ -102,6 +102,7 @@ function getTipo(valor){
if
(
esOperador
(
valor
))
return
"op"
;
if
(
valor
==
"="
)
return
"eq"
;
if
(
valor
==
"."
)
return
"dot"
;
return
valor
;
}
function
operar
(
a
,
b
,
op
){
...
...
@@ -121,4 +122,5 @@ function operar(a,b,op){
}
}
teclas
.
forEach
(
el
=>
el
.
addEventListener
(
'click'
,
escribir
));
\ No newline at end of file
teclas
.
forEach
(
el
=>
el
.
addEventListener
(
'click'
,
event
=>
{
escribir
(
event
.
target
.
innerHTML
)}));
document
.
addEventListener
(
'keypress'
,
event
=>
{
escribir
(
event
.
key
)})
\ 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