Need help on error handling if outside of even/odd array?? In the partyOfCity.
Thanks up front…
const evenArray = ['0','6','4','2']; //Even array for assignment
const oddArray = ['5','7','1','3']; //Odd array for assignment
const initialObj = { //Setup attributes for intial object from ATTUID in Webphone
'city': 'Peoria',
'name': 'David J Iman',
'defaultValue': 2
}
console.log(initialObj);
let numberOfNames = wordLength(initialObj.name); //Assign number of names that is in the name attribute of the initialObj
function wordLength(str) { //Calculation for number of words in a string
return str.split(' ').length;
}
const cityLength = initialObj.city.length; //Used to determine length of characters of the city name
const index = Math.round(cityLength/numberOfNames); //Compare index to length rounded to interger
//console.log(cityLength, '/', numberOfNames) - used for testing code
const partyOfCity = evenOrOdd(cityLength); //Create new const setting as even or odd from the value
function evenOrOdd(num) { //Used to determine even or odd
if (num % 2 === 0) {
return 'even';
}else {
return 'odd'
}
}
if (partyOfCity === 'even') {
if (index > evenArray.length) {
var result = Number(evenArray[evenArray.length]);
} else {
var result = Number(evenArray[index]);
}
} else {
if (index > oddArray.Length) {
var result = Number(oddArray[oddArray.length]);
} else {
var result = Number(oddArray[index]);
}
}
//console.log(partyOfCity) used for testing code
const finalObj = { //Create new final object from intial object
'city': initialObj.city,
'name': initialObj.name,
'defaultValue': initialObj.defaultValue + result
}
console.log(finalObj);