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

123
Views
Why I'm I getting undefined in front of the string?

function printOutput() {
    let str1 = window.prompt("Enter the first string");
    let str2 = window.prompt("Enter the Second string");
    let strTemp = str1;
    let strlen1 = str1.length;
    let strlen2 = str2.length;
    for (let i = 0; i < strlen1; i++) {
        for (let j = 0; j < strlen2; j++) {     
            if (str1.charAt(i) === str2.charAt(j)) {
                str1 = str1.replace(str1.charAt(i));
            }
        }
    }

    for (let i = 0; i < strlen2; i++) {

        for (let j = 0; j < strlen1; j++) {

            if (str2.charAt(i) === strTemp.charAt(j)) {
                str2 = str2.replace(str2.charAt(i));
            }
        }
    }
    console.log(str1,str2);
}
printOutput();

  1. Why I'm not getting the ouput properly.
  2. I'm getting undefined in front of the string ?
  3. What could be the solution ?
about 4 years ago · Santiago Gelvez
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!