跬步郎的博客 跬步郎的博客

——科员级项目管理师的奋斗历程

FreeCodeCamp备查簿(9、#231-#246--JavaScript基础)

20180920

231、Count Backwards With a For Loop

用for循环向后计数

// 请把你的代码写在这条注释以下
for (var i = 9; i>0; i-=2){
  myArray.push(i);
}

232、 Iterate Through an Array with a For Loop

遍历一个带有For循环的数组

// 请把你的代码写在这条注释以下
var total = 0;
for (var i=0; i < myArr.length; i++) {
  total += myArr[i];
}

233、Nesting For Loops

嵌套循环

  for (var i=0; i<arr.length; i++){
    for (var j=0; j<arr[i].length; j++){
      product = product * arr[i][j];
    }
  }

234、Iterate with JavaScript While Loops

JavaScript的while循环

var i = 0;
while(i < 5) {
  myArray.push(i);
  i++;
}

235、Profile Lookup

查找资料

// 请把你的代码写在这条注释以下
  for(var i = 0; i < contacts.length; i++){

    if(firstName == contacts[i].firstName){

            if(contacts[i].hasOwnProperty(prop)){

                  return contacts[i][prop];
            }
            else{
                return "No such property";
            }
     }                                        
   }
    return "No such contact";
// 请把你的代码写在这条注释以上

236、Generate Random Fractions with JavaScript

用JavaScript生成随机数,Math.random()是用来生成随机数的

  // 请把你的代码写在这条注释以下
  var ourFunction = Math.random();
  return ourFunction;

  // 请把你的代码写在这条注释以上

237、Generate Random Whole Numbers with JavaScript

用JavaScript生成随机整数

    // 请把你的代码写在这条注释以下

  return Math.floor(Math.random() *10);
}

238、Generate Random Whole Numbers within a Range

在指定范围内生产随机的整数

// 请把你的代码写在这条注释以下

function randomRange(myMin, myMax) {

  return Math.floor(Math.random() * (myMax - myMin + 1)) + myMin; // 请修改这一行

}

// 你可以修改这一行来测试你的代码

239、Sift through Text with Regular Expressions

用正则表达式筛选文本

var expression = /and/gi;  // 请修改这一行

240、Find Numbers with Regular Expressions

用正则表达式查找数字

var expression = /\d+/g;  // 请修改这一行

241、Find Whitespace with Regular Expressions

用正则表达式查找空白

// 请只修改这条注释以下的代码

var expression = /\s+/g;  // 请修改这一行

// 请只修改这条注释以上的代码

242、Invert Regular Expression Matches with JavaScript

将正则表达式与JavaScript相匹配

// 请只修改这条注释以下的代码

var expression = /\S/g;  // 请修改这一行

// 请只修改这条注释以上的代码

243、Create a JavaScript Slot Machine

创建一个老虎机

    // 请把你的代码写在这条注释以下
    slotOne = Math.floor(Math.random() * (3 - 1 + 1)) + 1;
    slotTwo = Math.floor(Math.random() * (3 - 1 + 1)) + 1;
    slotThree = Math.floor(Math.random() * (3 - 1 + 1)) + 1;


    // 请把你的代码写在这条注释以上

244、Add your JavaScript Slot Machine Slots

判断三个随机数是否相等

    // 请把你的代码写在这条注释以下
    if((slotOne !== slotTwo) || (slotTwo !== slotThree) || (slotThree !== slotOne))

      return null;


    // 请把你的代码写在这条注释以上

245、Bring your JavaScript Slot Machine to Life

把你的JavaScript老虎机带到生活中

    // 请把你的代码写在这条注释以下
    $($(".slot")[0]).html(slotOne);
    $($(".slot")[1]).html(slotTwo);
    $($(".slot")[2]).html(slotThree);


    // 请把你的代码写在这条注释以上

246、Give your JavaScript Slot Machine some Stylish Images

给你的JavaScript老虎机一些时髦的图片

    // 请把你的代码写在这条注释以下
    $($('.slot')[0]).html('<img src = "' + images[slotOne-1] + '">');
    $($('.slot')[1]).html('<img src = "' + images[slotOne-1] + '">');
    $($('.slot')[2]).html('<img src = "' + images[slotOne-1] + '">');
    // 请把你的代码写在这条注释以上
你的赞助,是对我辛勤耕耘的最大支持