Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
What are some simple ways to create a function with other functions

JavaScript - Visual Studio Code So, i am trying to create a simple random password generator, I have created 4 different arrays that all have a function to generate a random element out of each, my problem is I'm unsure on how to create a fifth function that can call the others and have them placed on the line with spaces (i.e. 5 happy cats singing). I am very fresh at programming, so I don't fully understand it, ill post what i have so far.

//Function to generate and display to console Word 1 - random number

function Word1() {

  var random = Math.floor(Math.random() * 9 + 1);
  return random


}

console.log(Word1());

// function to generate and display to console Word 2 - random emotion

function Word2() {

  var emotions = ['sad', 'happy', 'cheerful', 'angry', 'fear', 'surprise'];

  return emotions[Math.floor(Math.random() * emotions.length)];

}

console.log(Word2());

//function to generate and display to console Word 3 - random plural noun

function Word3() {

  var emotions = ['computer', 'day', 'car', 'flower', 'house', 'cat'];
  var plural = ['s'];
  var random = emotions[Math.floor(Math.random() * emotions.length)];
  var emotion_plural = random + plural;
  return emotion_plural


}

console.log(Word3());

//function to generate and display to console Word 4 - random verb

function Word4() {

  var verbs = ['running', 'walking', 'sleeping', 'talking', 'singing', 'sitting'];
var random = verbs[Math.floor(Math.random() * verbs.length)];

return random
}

console.log(Word4());

// function to create password one-line string
function passWord() {


  //??
}

console.log(passWord());
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Add this in password function:

    const part1 = word1()
    const part2 = word2()
    const part3 = word3()
    const part4 = word4()
    
    return part1 + part2 + part3 + part4

about 4 years ago · Juan Pablo Isaza Report

0

Call all your functions in the password function and concatenate the return values, for instance

function random(...array) {
  return array[array.length * Math.random() | 0];
}

function word1() {
  return Math.floor(Math.random() * 9 + 1);
}

function word2() {
  return random('sad', 'happy', 'cheerful', 'angry', 'fear', 'surprise');
}

function word3() {
  const plural = 's';
  return random('computer', 'day', 'car', 'flower', 'house', 'cat') + plural;
}

function word4() {
  return random('running', 'walking', 'sleeping', 'talking', 'singing', 'sitting');
}

function password() {
  return [word1(), word2(), word3(), word4()].join(' ');
}

console.log(password());

about 4 years ago · Juan Pablo Isaza Report

0

Try this *based on your code

function Word4() {

  var verbs = ['running', 'walking', 'sleeping', 'talking', 'singing', 'sitting'];

  return verbs[Math.floor(Math.random() * verbs.length)];

}

console.log(Word4());

// function to create password one-line string
function passWord() {

    return `${Word1()} ${Word2()} ${Word3()} ${Word4()}`

}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!