Skip to content

Pass all tests except for the special character requirement test #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
// Do work!
/* eslint-disable nonblock-statement-body-position */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution is very close to the solution @erick-pacheco has. Did you guys work together on this work?

function validatePassword(password) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting is a bit tough to read.

In VS Code, you can use the formatter. Menu > View > Command Palette. Type in "Format document"

function validatePassword(password) {
  let requirementsMet = true

  // Determine if the password length is more than or equal to 8 then..
  if (password.length >= 8) {
    requirementsMet = true
    // Using ASCII index and charCodeAt method (thanks to Jkearns!)
  } else {
    requirementsMet = false
  }
  // Test further requirements
  // Test for uppercase characters
  for (let i = 0; i < password.length; i++) {
    if (password.charCodeAt(i) >= 65 && password.charCodeAt(i) <= 90) {
      requirementsMet = true
      // Test for lowercase characters
    } else {
      requirementsMet = false
    }
    if (password.charCodeAt(i) >= 97 && password.charCodeAt(i) <= 122) {
      requirementsMet = true
      // Test for numeric value
    } else {
      requirementsMet = false
    }
    if (password.charCodeAt(i) >= 48 && password.charCodeAt(i) <= 57) {
      requirementsMet = true
      // Test for special characters
    } else {
      requirementsMet = false
    }
    if (password.charCodeAt(i) >= 33 && password.charCodeAt(i) <= 47) {
      requirementsMet = true
    } else {
      requirementsMet = false
    }
    requirementsMet = true

    requirementsMet = false
  }

  return requirementsMet
}

module.exports = validatePassword

let requirementsMet = true

// Determine if the password length is more than or equal to 8 then..
if (password.length >= 8) {
requirementsMet = true
// Using ASCII index and charCodeAt method (thanks to Jkearns!)
} else { requirementsMet = false }
// Test further requirements
// Test for uppercase characters
for (let i = 0; i < password.length; i++) {
if (password.charCodeAt(i) >= 65 && password.charCodeAt(i) <= 90) {
requirementsMet = true
// Test for lowercase characters
} else { requirementsMet = false }
if (password.charCodeAt(i) >= 97 && password.charCodeAt(i) <= 122) {
requirementsMet = true
// Test for numeric value
} else { requirementsMet = false }
if (password.charCodeAt(i) >= 48 && password.charCodeAt(i) <= 57) {
requirementsMet = true
// Test for special characters
} else { requirementsMet = false }
if (password.charCodeAt(i) >= 33 && password.charCodeAt(i) <= 47) {
requirementsMet = true
} else { requirementsMet = false }
requirementsMet = true

requirementsMet = false }

return requirementsMet
}


module.exports = validatePassword