let bandera=false;
let array=[];
let interval = setInterval(aumentarDecrecer, 2000);
function aumentarDecrecer(){
if(!bandera){
if(array.length<4){
array.push(array.length+1);
console.log(array);
}else{
bandera=true;
}
}else{
if(array.length>0){
array.pop();
console.log(array);
}else{
bandera=false;
}
}
}
Otra forma:
Otra forma:
<script>
let array=[];
function crecer(){
if (array.length==4) {
clearInterval(intervalo1);
decrecer();
intervalo1=setInterval(decrecer,2000);
}else{
array.push(array.length+1);
console.log(array);+
}
}
function decrecer(){
if (array.length==0) {
clearInterval(intervalo1);
crecer();
intervalo1=setInterval(crecer,2000);
}else{
array.pop();
console.log(array);
}
}
let intervalo1=setInterval(crecer,2000);
</script>
2.- Reloj:
//Cogemos la hora actual
let i, output = "";
let inicio = new Date().getTime();
for(i=1;i<=1e6;i++){
output +=1;
}
console.log(new Date().getTime()-inicio);
console.log(new Date().getTime()-inicio);
4.- Pedir datos y comprobarlos:
pedirDatos();
function pedirDatos() {
let nombre = prompt("Introduzca su nombre");
if (!/^[A-Z]/.test(nombre)) {
document.getElementById("error").innerHTML =
"Has introducido mal el nombre";
return;
}
let apellido = prompt("Introduzca sus apellidos");
let appelidos = apellido.split(" ");
if (appelidos.length != 2){
document.getElementById("error").innerHTML =
"Has introducido mal los apellidos";
return;
}
let email = prompt("Introduzca su email");
if (!/[a-zA-Z]+\.+[0-9]+@+[a-zA-Z]+\.+[a-zA-Z]+$/.test(email)) {
document.getElementById("error").innerHTML = "Has introducido mal el email";
return;
}
let pass = prompt("Introduzca su contraseña");
if (!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)([A-Za-z\d$@$!%*?&]|[^ ]){8}$/.test(pass)){
document.getElementById("error").innerHTML =
"Has introducido mal la contraseña";
return;
}
document.getElementById("name").innerHTML = nombre;
document.getElementById("apellido").innerHTML = apellido;
document.getElementById("email").innerHTML = email;
document.getElementById("pass").innerHTML = pass;
}
5.- Aumentar y disminuir ventana
let ventana;
function abrirVentana(){
ventana = window.open("","Ventana Ejercicio 5","width=400, height=400");
}
function cerrarVentana(){
ventana.close();
}
function disminuirVentana(){
ventana.resizeBy(-40,-40);
}
function posicionarVentana(){
ventana.moveTo(0,0);
}
function desplazarVentana(){
ventana.moveBy(20, 20);
}
Otra forma
<script>
let array=[];
function crecer(){
if (array.length==4) {
clearInterval(intervalo1);
decrecer();
intervalo1=setInterval(decrecer,2000);
}else{
array.push(array.length+1);
console.log(array);+
}
}
function decrecer(){
if (array.length==0) {
clearInterval(intervalo1);
crecer();
intervalo1=setInterval(crecer,2000);
}else{
array.pop();
console.log(array);
}
}
let intervalo1=setInterval(crecer,2000);
</script>
Otra forma
<script>
let array=[];
function crecer(){
if (array.length==4) {
clearInterval(intervalo1);
decrecer();
intervalo1=setInterval(decrecer,2000);
}else{
array.push(array.length+1);
console.log(array);+
}
}
function decrecer(){
if (array.length==0) {
clearInterval(intervalo1);
crecer();
intervalo1=setInterval(crecer,2000);
}else{
array.pop();
console.log(array);
}
}
let intervalo1=setInterval(crecer,2000);
</script>