mardi 28 avril 2020

My function is not invoked in another function

I'm trying to get my function to determine singular and plural errors. I wrote two functions in the global scope to be called in the main function called errorChecker but it refuses to execute. I'm wondering why? and what it is I am doing wrong. I am really new to coding so, please understand. below is the code. it does not run hence the errorChecker function does not detect the errors.

function errorChecker (num1, word1, num2, word2) {
  if (num1 === Number(num1) && word1 === String(word1) && num2 === Number(num2) && word2 === String(word2)) {
    console.log('all parameters are ok')
  } else {
    return false
  }
  if (wordChecker(word1) === true && (wordChecker(word2) === true)) {
    return true
  } else {
    console.log('invalid parameter')
  }
  if (singularChecker(num1, word1) === false && (pluralChecker(num2, word2) === false)) {
    console.log('correct singular and plurals')
  } else {
    return true
  }
}
// For checking function effectiveness
const num1 = 1
const word1 = 'minutes'
const num2 = 2
const word2 = 'minute'

console.log(errorChecker(num1, word1, num2, word2))
// function to set exact word parameters that can be used
function wordChecker (word) {
  switch (word) {
    case 'seconds':
    case 'second':
    case 'minutes':
    case 'minute':
    case 'hours':
    case 'hour':
    case 'days':
    case 'day':
      return true
    default:
      return false
  }
}

function pluralChecker (digit, letters) {
  switch (letters.toLowerCase()) {
    case 'seconds':
    case 'minutes':
    case 'hours':
    case 'days':
      if (digit !== 1) {
        return true
      } else {
        return false
      }
  }
}

function singularChecker (numz, wordz) {
  switch (wordz.lowerCase()) {
    case 'second':
    case 'minute':
    case 'hour':
    case 'day':
      if (numz === 1) {
        return true
      } else {
        return false
      }
  }
}

Aucun commentaire:

Enregistrer un commentaire