'<CODEHS> Im having an issue where my variable isn't storing my information

My classmate and I have encountered a problem while working on a project. We are making a password generator and we are not allowed to ask the teacher for help but he did say we can use other sources. The goal for the code is to give you random characters based on what you asked.

I've tried to use an array push to push the data to the next function but it just doesn't work when it reaches the part where its supposed to generate the random letters it just generates "undefined" The code is below:

var letters = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

var numbers = ["0","1","2","3","4","5","6","7","8","9"]

var symbols = ["!","@","#","$","%","&"]

var arr = [];

function start(){
println("Welcome to our password generator, with this generator you can create a strong password guaranteed to be acceptible on all sites!")

    var amount = readLine("How many characters should be in your password? ")
    
    password();

}

function password(){
var amountL = readLine("How many letters should be in it? ");

    for(var i = 0; i < amountL;i++){
        var number = Randomizer.nextInt(0,25);
        var rand = println(letters[number]);
        var generatePasswords = rand
        println(generatePasswords)
        arr.push(rand)
    }
    
    var amountN = readLine("How many numbers should be in it? ");
    
    for(var i = 0; i < amountN;i++){
        var number = Randomizer.nextInt(0,10);
        var rando = println(numbers[number]);
        var generatePasswords = println(rando)
        println(generatePasswords)
        arr.push(rando)
    }
    
    var amountS = readLine("How many symbols should be in it? ");
    
    for(var i = 0; i < amountS;i++){
        var number = Randomizer.nextInt(0,6);
        var random = println(symbols[number]);
        var generatePasswords = println(random)
       
        println(generatePasswords)
        arr.push(random)
       
    }
    
    println("you're new password is " + arr );

}


Solution 1:[1]

Your code seems to be mixing bits of syntax from java and javascript, but I'm not going to try and decode that line-by-line. Instead, I'll focus on your question: you're using println to get the value of an array.

I'm not sure where your alias for println comes from, honestly, but unless it works differently from every other print function I've ever seen it probably doesn't return its argument, just write it to stdout. Try replacing println(letters[number]) with letters[number] and see if that works. If it does, do the same in the rest of the randomizer blocks.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shonee Freed-Doerr