www.webdeveloper.com
Results 1 to 11 of 11

Thread: array function

  1. #1
    Join Date
    Aug 2014
    Posts
    111

    array function

    is this function returning an array ?

    Code:
     function rq() {
         var a = getRandomInt(0, 100),
             b = getRandomInt(0, 100),
             operator = "+-*" [getRandomInt(0, 3)],
             answer = operator === "+" ? a + b : operator === "-" ? a - b : operator === "*" ? a * b:0;
    
    
    
         return ["what is " + a + operator + b, answer]
     }

  2. #2
    Join Date
    Nov 2010
    Posts
    1,102
    it's trying to...

  3. #3
    Join Date
    Aug 2014
    Posts
    12
    Sure, array with 2 elements.

  4. #4
    Join Date
    Aug 2014
    Posts
    111
    Quote Originally Posted by KryDos View Post
    Sure, array with 2 elements.
    are you absolutly sure ? also , how can i check if its an array ?

  5. #5
    Join Date
    Aug 2014
    Posts
    12
    Quote Originally Posted by gautamz07 View Post
    how can i check if its an array ?
    You can use Array.isArray function.
    Something like that:
    if(Array.isArray(rq())) {
    alert('is array');
    }
    else {
    alert('(><)');
    }

  6. #6
    Join Date
    Aug 2014
    Posts
    111
    Thanks @KryDos ,

    am i doing it right http://jsfiddle.net/gautamz07/xonL4rwj/

    because the method does't seem to be appearing ? or maybe i'am just just having a blonde day today ...

  7. #7
    Join Date
    Aug 2014
    Posts
    12
    am i doing it right
    Yes. You're doing it right but you have no any alerts because you have no getRandomInt function. It's a not "standard library" function. You have to write it first. Like this - http://jsfiddle.net/f6qbgrzy/

  8. #8
    Join Date
    Aug 2014
    Posts
    12
    Opps. Like this - http://jsfiddle.net/4cu8a2m8/1/
    Previous link is wrong.

    Damn How to edit posts here?

  9. #9
    Join Date
    Aug 2014
    Posts
    111
    well i am aware that , its not a built in function , just forgot to add i in the code .

    I donno how you edit post here , BTW , FAQ section may be of help . Thanks a ton for ur help @KryDos.

  10. #10
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,507
    you can use typeOf to get the string name of the object, array, function, boolean ... ...

    In JavaScript, an array is identified as any element that has [] brackets or has information encased in [] brackets, so return ["what is " + a + operator + b, answer] is returning an array.

    if you just wanted a string then you would return "what is " + a + operator + b, answer; and remember that you should be terminating the ends of your code lines with a ; semi-colon.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  11. #11
    Join Date
    Aug 2014
    Posts
    111
    thanks for ur elaborate answer . I learnt something new . TY .

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles