MessageMixer

Very stuck here. I have even watched the video solution and duplicated what I saw there and it still tells me that the function I am using doesn’t exist even though it is declared in the messageMixer.js file.

So here is the module file messageMixer.js

const MessageMixer = {};

MessageMixer.countCharacter = function(inputString, inputCharacter) {
  let count = 0;
  let string = inputString.toLowerCase();
  let character = inputCharacter.toLowerCase();
    for (let i = 0; i < string.length; i++) {
      if (string[i] === character) {
         count++;
      }
    }
  return count; 
};

MessageMixer.capitalizeFirstCharacterOfWords = function (string) {
  let arr = string.split(" ");  
    for (let i = 0; i < arr.length; i++) {  
      let word = arr[i];
        arr[i] = word[0].toUpperCase() + word.substring(1); 
    }
  return arr.join(" "); 
};

MessageMixer.reverseWord = function(word) {
  return word.split("").reverse().join("");
};

MessageMixer.reverseAllWords = function(sentence) {
  let words = sentence.split(" ");
    for (let i = 0; i < words.length; i++) {
      words[i] = MessageMixer.reverseWord(words[i]);
    }
   return words.join(" ");
};


MessageMixer.replaceFirstOccurence = function(string, toBeReplaced, replaceWith) {
  return string.replace(toBeReplaced, replaceWith);
};


MessageMixer.replaceAllOccurrences = function(string, toBeReplaced, replaceWith) {
  return string.split(toBeReplaced).join(replaceWith);
};

MessageMixer.encode = function(string) {
  let replacementObject = { "a": "@", "s": "$", "i": "!", "o":"0" };
    for (let key in replacementObject) {
      string = MessageMixer.replaceAllOccurrences(string, key, replacementObject[key]); 
    }	
    return string;
};

module.export = MessageMixer;

This should define the function MessageMixer.countCharacter to be used in the message.js file as

console.log(MessageMixer.countCharacter(“What is the color of the sky?”, “t”));

But it tells me that MessageMixer.countCharacter is not a function!

I am at wit’s end. What is going on?

Hey @arc4683563979, I formatted your code. Go ahead and check out this post as a reference on how to do this for future topics.

As for the issue, my first instinct - which could be wrong, as I’m not hugely familiar with JavaScript - would be to ask whether you’re importing that module into message.js in order to use the functionality defined in messageMixer.js

Yes it is intended as an exercise in using imported modules. So message.js imports messageMixer.js