Home > Mobile >  How to send a variable as a response from function in another file?
How to send a variable as a response from function in another file?

Time:01-09

So I'm making a rather funny program which is a love calculator and this is just to practice JS. So here what names the user enters doesn't really matter it just uses a function to generate a random number and displays it as the lovescore. Now the problem is that the code works fine when everything is in one file. But when I make different files for different functions for example here I'm trying to make a different file for the genrateNumber function and export it, it does not work. I'm looking to somehow send the the loveScore variable as a response once the function is called in. The program works fine when everything is in one file.

Index.js

import generateNumber from './generateNumber.js'

const createSentence = (male, female) => {
  console.log(`${female} feels ${loveScore}% for ${male}`);
}

const calculateLoveScore = (male, female) => {
  generateNumber();
  if (loveScore == 100 && loveScore >= 98) {
    createSentence(male, female, loveScore);
    console.log(`${female} is the one for ${male}           
  • Related