今晚发现一个比较有趣的js过关游戏,分享下

本人js是今年下半年开始真正入手啊,感觉这js世界丰富程度真的超出我想象

晚上偶然间看到别人在群里问做什么题目的,跟踪后发现是个js过关游戏,而且全是英文,兴趣就来了偷笑

网站地址为:http://toys.usvsth3m.com/javascript-under-pressure/

javascript-under-pressure

总共有五关,都是些比较基础的题目,对本人水平测试玩玩够了~

全部答题完成花了15分钟 难过,把每关的代码贴下,有兴趣的可以看看,有觉得写得不好的可以攻击哈~求赐教!

对大牛来说很基础,有兴趣的童鞋们可以玩下哈

第一关

 

[javascript] view plaincopyprint?
 
  1. function doubleInteger(i) {  
  2.    // i will be an integer. Double it and return it.  
  3.    return i*=2;  
  4. }  

 

 

第二关

 

[javascript] view plaincopyprint?
 
  1. function isNumberEven(i) {  
  2.    // i will be an integer. Return true if it's even, and false if itisn't.  
  3.    if(i %2 === 0)  
  4.        return true;  
  5.    return false;  
  6. }  

 

 

 第三关

 

[javascript] view plaincopyprint?
 
  1. function getFileExtension(i) {  
  2.    // i will be a string, but it may not have a file extension.  
  3.    // return the file extension (with no period) if it has one, otherwisefalse  
  4.    var j = i.lastIndexOf('.');  
  5.    if(j===-1)  
  6.        return false;  
  7.    return i.substring(j+1);  
  8. }  


第四关

 

 

[javascript] view plaincopyprint?
 
  1. function longestString(i) {  
  2.    // i will be an array.  
  3.    // return the longest string in the array  
  4.    var result = '';  
  5.    for(var j = 0;j < i.length;j++)  
  6.     {  
  7.        if(typeof(i[j])=="string" && (i[j].length >result.length))  
  8.            result = i[j].toString();  
  9.     }  
  10.     return result;  
  11.   }  


第五关

 

 

[javascript] view plaincopyprint?
 
    1. function arraySum(i) {  
    2.    // i will be an array, containing integers, strings and/or arrays likeitself.  
    3.    // Sum all the integers you find, anywhere in the nest of arrays.  
    4.    var result = 0;  
    5.    for(var j = 0;j<i.length;j++)  
    6.     {  
    7.        if(typeof(i[j]) == "number")  
    8.            result +=i[j];  
    9.        else if(Object.prototype.toString.call(i[j]) === '[object Array]')  
    10.            result +=arraySum(i[j]);  
    11.     }  
    12.    return result;  
    13. }  

posted on 2013-11-03 23:15  Charles.  阅读(1765)  评论(0)    收藏  举报

导航