JavaScript

This password validation function in Javascript looks really awful to be honest ๐Ÿ˜ƒ Thoughts ?


 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
47
48
49
50
51
52
53
54
55
function checkPassword() {
    const val = document.querySelector('.session-input > #user_password').value
    const confirm = document.querySelector('.session-input > #user_password_confirmation').value
    const email = document.querySelector('.session-input > #user_email').value.split('@')[0]

    if (val && email) {
        if (val.length < 16) {
            document.querySelector('.pw-length').classList.remove('success')
            document.querySelector('.pw-length').classList.add('error')
        } else {
            document.querySelector('.pw-length').classList.remove('error')
            document.querySelector('.pw-length').classList.add('success')
        }

        if (val.search(/[a-z]/) < 0 || val.search(/[A-Z]/) < 0) {
            document.querySelector('.lower-upper').classList.remove('success')
            document.querySelector('.lower-upper').classList.add('error')
        } else {
            document.querySelector('.lower-upper').classList.remove('error')
            document.querySelector('.lower-upper').classList.add('success')
        }

        if (val.search(/[0-9]/) < 0 || val.search(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/) < 0) {
            document.querySelector('.num-char').classList.remove('success')
            document.querySelector('.num-char').classList.add('error')
        } else {
            document.querySelector('.num-char').classList.remove('error')
            document.querySelector('.num-char').classList.add('success')
        }

        if (val != confirm) {
            document.querySelector('.pw-match').classList.remove('success')
            document.querySelector('.pw-match').classList.add('error')
        } else {
            document.querySelector('.pw-match').classList.remove('error')
            document.querySelector('.pw-match').classList.add('success')
        }

        if (checkIdenticalConsecutive()) {
            document.querySelector('.consecutive').classList.remove('success')
            document.querySelector('.consecutive').classList.add('error')
        } else {
            document.querySelector('.consecutive').classList.remove('error')
            document.querySelector('.consecutive').classList.add('success')
        }

        if (val.search(/hydra/) >= 0 || val.toLowerCase().search(email.toLowerCase()) >= 0) {
            document.querySelector('.name-email-hydra').classList.remove('success')
            document.querySelector('.name-email-hydra').classList.add('error')
        } else {
            document.querySelector('.name-email-hydra').classList.remove('error')
            document.querySelector('.name-email-hydra').classList.add('success')
        }
    }
}
S

Member

by Skaidar , in category: JavaScript , 2 months ago
2 answers last reply 2 months ago from adelia_boyer

The senior front enders in the company I recently joined are trying to convince me that it's ok to write code like this


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
divisionHelperTriangle(length, score) {
    if (score === 2) {
      return length / 28
    }
    if (score === 3) {
      return length / 26
    }
    if (score === 4) {
      return length / 26.5
    }
    if (score === 5) {
      return length / 27.5
    }
    if (score === 6) {
      return length / 26
    }
    if (score >= 7) {
      return length / 25
    }
    return length / 30
  }


Nice Module Export Function in Javascript ๐Ÿ˜€

1
2
3
module.exports = function(settings, done) {
ย  ย  return '3912';
};


When you are really love setTimeout in Javascript

1
2
3
4
5
setTimeout("__zoomed_div_style__.left = parseInt(__zoomed_div_style__.left) - " + (diff_width * 0.1) + " + 'px'", 50);
setTimeout("__zoomed_div_style__.left = parseInt(__zoomed_div_style__.left) - " + (diff_width * 0.1) + " + 'px'", 100);
setTimeout("__zoomed_div_style__.left = parseInt(__zoomed_div_style__.left) - " + (diff_width * 0.1) + " + 'px'", 150);
setTimeout("__zoomed_div_style__.left = parseInt(__zoomed_div_style__.left) - " + (diff_width * 0.1) + " + 'px'", 200);
setTimeout("__zoomed_div_style__.left = parseInt(__zoomed_div_style__.left) - " + (diff_width * 0.1) + " + 'px'", 250);


Member

by letha , in category: JavaScript , 8 months ago
no answers

List of Constants in Javascript

 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
// Variables of elements and inputs to manipulate
const dmContainer = document.querySelector('#dmContainer');
const nameMotor = document.querySelector('#nameMotor');
const chasisBtn = document.querySelector('#chasis-btn');
const chasisModal = document.querySelector('#chasis-modal');
const chasisType = document.querySelector('#chasisType');
const colorChasis = document.querySelector('#color-chasis');
const modalPop = document.querySelector('.modalPop');
const inputName = document.querySelector('#inputName');
const motorsName = document.querySelector('.motorsName');
const behindImg = document.querySelector('.defMotor');
const tyresBtn =document.querySelector('#tyres-btn');
const tyresModal = document.querySelector('#tyres-modal');
const tyresType = document.querySelector('#tyres-type');
const handleBtn = document.querySelector('#handle-btn');
const handleModal = document.querySelector('#handle-modal');
const handleType = document.querySelector('#handle-type');
const headBtn = document.querySelector('#head-btn');
const headModal = document.querySelector('#head-modal');
const headType = document.querySelector('#head-type');
const mufflerBtn = document.querySelector('#muffler-btn');
const mufflerModal = document.querySelector('#muffler-modal');
const mufflerType = document.querySelector('#muffler-type');
const brakeBtn = document.querySelector('#brake-btn');
const brakeModal = document.querySelector('#brake-modal');
const brakeType = document.querySelector('#brake-type');
const frontFlash = document.querySelector('.flash-chasis-f');
const rearFlash = document.querySelector('.flash-chasis-r');
const flashSelect = document.querySelector('#flashSelect');
const doneChasisย  = document.querySelector('#doneChasis');
const motorsName2 = document.querySelector('#motors-name');
const motorsName3 = document.querySelector('#motors-name1');
const colorHead =document.querySelector('#color-head');
const colorMuffler = document.querySelector('#color-muffler')


You will never speak in Javascript language ๐Ÿ˜ƒ

1
2
3
4
5
6
7
console.log(parseInt(0.5)); // 0
console.log(parseInt(0.05)); // 0
console.log(parseInt(0.005)); // 0
console.log(parseInt(0.0005)); // 0
console.log(parseInt(0.00005)); // 0
console.log(parseInt(0.000005)); // 0
console.log(parseInt(0.0000005)); // 5


Initialize multiple times instead of using comma in jQuery

1
2
3
4
5
6
7
8
9
$(document).ready(function () {
	$("a").easyTooltip()
});
$(document).ready(function () {
	$("img").easyTooltip()
});
$(document).ready(function () {
	$("span").easyTooltip()
});


When one setTimeout in Javascript is not enough ๐Ÿ˜

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
setTimeout(()=>{

  $('.arrowDashed, .OG1ficon, .OG1LeaderLeft, .OG1LeaderRight').css({'transition':'1s', 'opacity':'1'});
  map.opacity.inside([1,0,0], 1);

  setTimeout(()=>{
    map.animate.og1Results(50, 2);
    $('#anotherIdToCall6').css({'transition':'1s', 'opacity':'1'})

    setTimeout(()=>{
      map.opacity.main([1,1,0], 1)
      $('.IGTopContestWrap').css({'transition':'0s', 'opacity':'0'});
      $('.IGBottomContestWrap').css({'transition':'0s', 'opacity':'0'});
    },650)

  }, 1250)

}, 100)


Member

by letha , in category: JavaScript , 8 months ago
no answers

I think too many parentNode in JavaScript ๐Ÿ˜

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
for(var i=obj.parentNode.parentNode.childNodes.length;i>=0;i--)
{
  if(obj.parentNode.parentNode.childNodes[i]!=undefined)
  {
    if(obj.parentNode.parentNode.childNodes[i].tagName=="TR")
    {
      if (obj.parentNode.parentNode.childNodes[i].childNodes[0]!=undefined){
        for (var j=obj.parentNode.parentNode.childNodes[i].childNodes.length;j>=0;j--)
        {
          if(obj.parentNode.parentNode.childNodes[i].childNodes[j]!=undefined){
            if(obj.parentNode.parentNode.childNodes[i].childNodes[j].childNodes[0].tagName=="TABLE"){
              obj.parentNode.parentNode.childNodes[i].childNodes[j].childNodes[0].childNodes[0].childNodes[0].childNodes[0].attributes.getNamedItem("background").value = "images/category_n.png";
            }
          }
        }
      }
    }
  }
}


Member

by letha , in category: JavaScript , 8 months ago
no answers

Check hash function in Javascript

1
2
3
4
5
6
7
function checkHash(){
    if(getCookie("needHash") != null){
        if(getCookie("needHash").length>0){
            ensureHash(getCookie("needHash"));
        }
    }
}