zoukankan      html  css  js  c++  java
  • [Javascript] Create Objects

    var vehicle1 = {type: "Motorboat", capacity: 6, storedAt: "Ammunition Depot"};
    var vehicle2 = {type: "Jet Ski", capacity: 1, storedAt: "Reef Dock"};
    var vehicle3 = {type: "Submarine", capacity: 8, storedAt: "Underwater Outpost"};

    //TO FIND a vehicle

    var vehicle1 = {type: "Motorboat", capacity: 6, storedAt: "Ammunition Depot"};
    var vehicle2 = {type: "Jet Ski", capacity: 1, storedAt: "Reef Dock"};
    var vehicle3 = {type: "Submarine", capacity: 8, storedAt: "Underwater Outpost"};
    var vehicles = [vehicle1, vehicle2, vehicle3];
    var findVehicle = function(name, list){
      for(var i = 0; i < list.length; i++){
        if(list[i].name === name){
            return i;
        }
      };
     findVehicle("Submarine");
    };
    var vehicle1 = {type: "Motorboat", capacity: 6, storedAt: "Ammunition Depot"};
    var vehicle2 = {type: "Jet Ski", capacity: 1, storedAt: "Reef Dock"};
    var vehicle3 = {type: "Submarine", capacity: 8, storedAt: "Underwater Outpost"};
    vehicle1.capacity += 4;
    vehicle2.submersible = false;
    vehicle3.weapon = "Torpedoes";
    vehicle1.submersible = false;
    vehicle2.weapon = "Lasers";
    vehicle3.capacity *= 2;
    vehicle1.weapon = "Rear-Mounted Slingshot";
    vehicle3.submersible = true;
    vehicle3["# of weapons"] = 8;
    vehicle2["# of weapons"] = 4;
    vehicle1["# of weapons"] = 1;

    delete a obj or a attriable.

    var superBlinders = [ ["Firelight", 4000], ["Solar Death Ray", 6000], ["Supernova", 12000] ];
    var lighthouseRock = {
      gateClosed: true,
      bulbs: [ 200, 500, 750 ],
      capacity: 30,
      secretPassageTo: "Underwater Outpost"
    };
    delete lighthouseRock.bulbs;
    lighthouseRock.weaponBulbs = superBlinders;
    console.log(lighthouseRock.weaponBulbs[2][0]);

    PIRATES AHOY! Despite protests of “I’m a coder, not a fighter”, it’s time for the ranger-devs to get over to the Lighthouse and throw down!

    In the editor is a modified object literal for Lighthouse Rock, with the new blinders now showing up in a property. Additionally, a new property, numRangers, has been added to track how many rangers are fighting for the Ocean of Objects at the Lighthouse.

    Your goal is to build a declared function that adds the following three rangers, in order and as complete objects, to the Lighthouse Rock object itself:

    1. name: “Nick Walsh”, skillz: “magnification burn”, station: 2
    2. name: “Drew Barontini”, skillz: “uppercut launch”, station: 3
    3. name: “Christine Wong”, skillz: “bomb defusing”, station: 1

    Each added ranger object should become its own property within lighthouseRock, specifically ranger1ranger2, and ranger3. Additionally, as you add a ranger, increment the number of rangers present using the existing numRangers property.

    In order to add your newly created objects to the Lighthouse, your function should accept a location parameter, which will represent that object. To help us check your function, order your function parameters as locationnameskillz, and station.

    Name your new function addRanger. Lastly, when the function has been built, call it three times, with the appropriate data each time, to effectively add all three rangers to lighthouseRock.

    var superBlinders = [ ["Firestorm", 4000], ["Solar Death Ray", 6000], ["Supernova", 12000] ];
    var lighthouseRock = {
      gateClosed: true,
      weaponBulbs: superBlinders,
      capacity: 30,
      secretPassageTo: "Underwater Outpost",
      numRangers: 0
    };
    function addRanger(location, name, skillz, station){
      location.numRangers++;
      location["ranger" + location.numRangers] = {name: name, skillz: skillz, station: station};
    }
    addRanger(lighthouseRock, "Nick Walsh", "magnification burn", 2);
    addRanger(lighthouseRock, "Drew Barontini", "uppercut launch", 3);
    addRanger(lighthouseRock, "Christine Wong", "bomb defusing", 1);
  • 相关阅读:
    2015/8/28 回校正常学习工作
    Asp.net自定义控件开发任我行(3)-Render
    Asp.net自定义控件开发任我行(2)-TagPrefix标签
    Asp.net自定义控件开发任我行(1)-笑傲江湖
    ET采集阿里妈妈淘宝客商品规则
    淘宝API还能用来采集数据吗?taobao.item.get 接口还能用吗?
    淘宝api升级,无法采集淘宝的数据,taobao.item.get 和taobao.taobaoke.items.get都不能用
    用firefox浏览器访问localhost,apache http server 已停止工作
    淘宝客网站怎么批量采集淘宝商品,方维采集淘宝数据思路
    方维购物分享系统怎么样,方维系统安全性检测
  • 原文地址:https://www.cnblogs.com/Answer1215/p/3898455.html
Copyright © 2011-2022 走看看