Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda