₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,346,546 members, 8,523,818 topics. Date: Tuesday, 24 November 2026 at 12:56 AM

Toggle theme

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

Nairaland Forum › Science/Technology › Programming › I Bet You Cant Do This With Javascript, *check Out* (1344 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 Javascript • Hashtag Highlighting Like Twitter With Javascript • 2 • 3 • 4

Data Encryption With Python-how To Encrypt A Textfile Using Python • Any Good Webdeveloper In Enugu? • Collins Nji Becomes The First African To Win Google’s Code-in Competition.