₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,331,189 members, 8,449,043 topics. Date: Tuesday, 21 July 2026 at 09:02 AM

Toggle theme

I Bet You Cant Do This With Javascript, *check Out* - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingI Bet You Cant Do This With Javascript, *check Out* (1314 Views)

1 Reply (Go Down)

I Bet You Cant Do This With Javascript, *check Out* by Cybergenius(op): 4:01pm On Nov 01, 2014
Lets see how you know javascript!
--
Write a function that takes an argument and returns that argument

idf = identify(3);
idf() //3
Re: I Bet You Cant Do This With Javascript, *check Out* by Cybergenius(op):
My attempt

function identify(q){
return q;
}

idf = identify(2);

idf() //"TypeError: 2(value of expression idf) is not object"
Re: I Bet You Cant Do This With Javascript, *check Out* by blueyedgeek(m): 5:14pm On Nov 01, 2014
This should be pretty easy to implement.

function identify(val){
this.val = val;
return val;
}
identify(3) --> 3
identify("Tunde" ) --> "Tunde"
identify({name: "Osewa"}) --> Object {name: "Osewa"}

Re: I Bet You Cant Do This With Javascript, *check Out* by Cybergenius(op): 5:36am On Nov 02, 2014
blueyedgeek:
This should be pretty easy to implement.

function identify(val){
this.val = val;
return val;
}
identify(3) --> 3
identify("Tunde" ) --> "Tunde"
identify({name: "Osewa"}) --> Object {name: "Osewa"}

you are wrong you didn't follow the rule, where is the idf variable?

function identify(q){
return function(){
return q;
}
}

idf = identify(3);
idf() //3
Re: I Bet You Cant Do This With Javascript, *check Out* by blueyedgeek(m): 7:02am On Nov 02, 2014
Cybergenius:
you are wrong you didn't follow the rule, where is the idf variable?

function identify(q){
return function(){
return q;
}
}

idf = identify(3);
idf() //3
Oh, I'm supposed to set a variable equal to the result of calling the identify function. Why do I need to call it like a function?
Re: I Bet You Cant Do This With Javascript, *check Out* by dhtml(m): 8:29am On Nov 02, 2014
Try this:
function identify(){return arguments[0];}
alert(identify(3));
Try zat
Re: I Bet You Cant Do This With Javascript, *check Out* by bot101(m): 11:47am On Nov 02, 2014
.
Re: I Bet You Cant Do This With Javascript, *check Out* by Cybergenius(op): 5:38pm On Nov 03, 2014
blueyedgeek:
Oh, I'm supposed to set a variable equal to the result of calling the identify function. Why do I need to call it like a function?
thats the challenge
Re: I Bet You Cant Do This With Javascript, *check Out* by dhtml(m): 7:39pm On Nov 03, 2014
Your post was not clear from the begining. . .
Re: I Bet You Cant Do This With Javascript, *check Out* by cyrielo(m): 11:05am On Nov 04, 2014
baby challenge
Re: I Bet You Cant Do This With Javascript, *check Out* by Cybergenius(op): 5:04pm On Nov 04, 2014
1 Reply

Building A Word Scramble Game With Javascript (text Based)How To Get A User IP Address With JavascriptHashtag Highlighting Like Twitter With Javascript234

What Browser Should I Use? Say Goodbye To Tracking And Say HI! To Privacy!Where Can I Find A Code Academy In Lagos, Close To Ogudu Or Anthony?Programmers Psychological Advice Needed Plz