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

204
Views
Looking for a function that takes three arguments (x, y, z) and checks if the type of all three is a string

Don't know what to put before the for loop. Don't know if I need an if/else statement. Trying to have it display in the console if items in an array are strings. So I know I need consol.log

var stringOne = isString('rob','bob','carl')

function isString() {
//I dont know what to put before for loop

    for(let i = 0; i < arguments.length; i++) {
        // Dont know if i need an if/else statement
        // Trying to have it display in the console if items in an array are strings
        // So I know I need consol.log
    }

}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

every would be appropriate here, and doing I/O (like console.log) is better left outside of the function. The name of the function suggests that it should return a boolean (true/false):

function isString(...args) {
    return args.every(s => typeof s === "string");
}

console.log(isString('rob','bob','carl'));

about 4 years ago · Juan Pablo Isaza Report

0

Because it seems like you're a beginner, I will expand upon the code that you currently have, although @trincot did the best solution.

In a for loop, you can return a value so the loop won't continue. Because you only need to check if any of them are false, may it be in position 0, 1 or 2 in the array, you can return "false" immediately.

If there are only strings, the loop will continue until it ends, and then return "true" at the end of the method.

So you don't need any code before the for loop, only an if statement that returns "false" if any of the items in the array isn't a string.

var stringOne = isString('rob','bob','carl')
var stringTwo = isString('rob','bob', 1)

function isString() {
    for(let i = 0; i < arguments.length; i++) {
      if (typeof arguments[i] != 'string') {
        return false
      }
    }

  return true
}

console.log({stringOne});
console.log({stringTwo});

about 4 years ago · Juan Pablo Isaza Report

0

Something like this in the loop ought to do it:

this_arg = arguments[i];
if (typeof this_arg === 'string') console.log("arg number " + i + " is a string");

It shows how to do it a bit here

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!