I have written a script to check whether a sentence is a pangram or not.
I am trying to remove the last element in an array. In order to create a gramatically correct sentence e.g. 'X, Y and Z.' I have tried using .pop() which as I understand removes the last element of the array but also returns the element.
Despite using 'let'. The .pop() removes the object from the original array, not just the new one declared within the if statement.
Hope someone can help out and point me in the right direction with this one.
// Pangram Checker
var sentence = (('Two rien Jocks hlp fx my big quiz').toUpperCase()).split("")
var alpha_array = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ').split("")
missingLetters = [];
for (var i = 0; i < alpha_array.length; i++) {
if (sentence.includes(alpha_array[i])) {
} else {
missingLetters.push(alpha_array[i])
}
}
if (missingLetters.length >=3) {
let arr = missingLetters.pop()
console.log('The letters ' + arr + ' and ' + missingLetters[(missingLetters.length - 1)] + ' are missing from the sentence.')
}
if (missingLetters.length ==2) {
console.log('The letters ' + missingLetters[0] + ' and ' + missingLetters[1] + ' are missing from the sentence.')
}
if ( missingLetters.length ==1) {
console.log('The letter ' + missingLetters[0] + ' is missing from the sentence.')
}
if (missingLetters.length == 0) {
console.log('This sentence is a pangram, it contains all the letters of the Alphabet!')
}