challenge-response

From 1 to 100, print “ping” if multiple of 3, “pong” if multiple of 5, or else print the number

醉酒当歌 提交于 2019-11-29 23:21:34
I just came home from a job interview, and the interviewer asked me to write a program: It should, count from 1 to 100, and print... If it was multiple of 3, "ping" If it was multiple of 5, "pong" Else, print the number. If it was multiple of 3 AND 5 (like 15), it should print "ping" and "pong". I chose Javascript, and came up with this: for (x=1; x <= 100; x++){ if( x % 3 == 0 ){ write("ping") } if( x % 5 == 0 ){ write("pong") } if( ( x % 3 != 0 ) && ( x % 5 != 0 ) ){ write(x) } } Actualy, I left very unhappy with my solution, but I can't figure out a better one. Does anyone knows a better

How can one make a web-site accessible only when someone has a dongle?

天涯浪子 提交于 2019-11-29 12:41:02
问题 Suppose you want to add an extra layer of credentials on top of a SSL-encrypted login/password, but you don't want to increase complexity to the user. Is there a way to add the requirement of the possession of a dongle to web-server authentication schemes with existing cross-platform browser capabilities? In other words, to get access to the web-site, you would need a username, password, and a USB dongle that has been plugged into the client computer. The dongle would presumably do some sort

From 1 to 100, print “ping” if multiple of 3, “pong” if multiple of 5, or else print the number

假如想象 提交于 2019-11-28 19:22:05
问题 I just came home from a job interview, and the interviewer asked me to write a program: It should, count from 1 to 100, and print... If it was multiple of 3, "ping" If it was multiple of 5, "pong" Else, print the number. If it was multiple of 3 AND 5 (like 15), it should print "ping" and "pong". I chose Javascript, and came up with this: for (x=1; x <= 100; x++){ if( x % 3 == 0 ){ write("ping") } if( x % 5 == 0 ){ write("pong") } if( ( x % 3 != 0 ) && ( x % 5 != 0 ) ){ write(x) } } Actualy, I

Javascript function challenge add(1,2) and add(1)(2) both should return 3

北城余情 提交于 2019-11-28 09:29:57
A friend of mine challenged me to write a function that works with both of these scenarios add(2,4) // 6 add(2)(4) // 6 My instinct was the write an add() function that returns itself but I'm not sure I'm heading in the right direction. This failed. function add(num1, num2){ if (num1 && num2){ return num1 + num2; } else { return this; } } alert(add(1)(2)); So I started reading up on functions that return other functions or return themselves. http://davidwalsh.name/javascript-functions JavaScript: self-calling function returns a closure. What is it for? JavaScript: self-calling function returns

Javascript function challenge add(1,2) and add(1)(2) both should return 3

混江龙づ霸主 提交于 2019-11-27 03:06:20
问题 A friend of mine challenged me to write a function that works with both of these scenarios add(2,4) // 6 add(2)(4) // 6 My instinct was the write an add() function that returns itself but I'm not sure I'm heading in the right direction. This failed. function add(num1, num2){ if (num1 && num2){ return num1 + num2; } else { return this; } } alert(add(1)(2)); So I started reading up on functions that return other functions or return themselves. http://davidwalsh.name/javascript-functions