I created two functions and a global object data. I am trying to split what a person inputs inside a text area into individual strings and push them in the global object. The Error I have says userInputParam.split is not a function.For the sake of brevity I have excluded the updateUserInput function which is attached to a click event.
let data = {
userInput: [],
splittedInput: [],
slicedInput: [],
};
function updateUserInput(data) {
if (data.userInput.length == 0) {
// console.log("You can do this Panda!")
data.userInput.push(input.value);
//input.value is what a user inputs in a textarea.
splitUserInput(data.userInput)
}
}
function splitUserInput (userInputParam){
let splittedInput = userInputParam.split(/([*/+-])/)
//console.log(splittedInput)
}
The argument to splitUserInput should be the input value, not the array that you pushed it onto.
splitUserInput should return the result of splitting, and then you can push that onto data.sp;littedInput.
function updateUserInput(data) {
if (data.userInput.length == 0) {
// console.log("You can do this Panda!")
data.userInput.push(input.value);
//input.value is what a user inputs in a textarea.
data.splittedInput.push(splitUserInput(data.userInput));
}
}
function splitUserInput (userInputParam){
let splittedInput = userInputParam.split(/([*/+-])/)
return splittedInput;
}