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);

[Javascript] Create Objects的更多相关文章

  1. [Javascript] Create an Image with JavaScript Using Fetch and URL.createObjectURL

    Most developers are familiar with using img tags and assigning the src inside of HTML. It is also po ...

  2. Javascript笔记--Objects

     Javascript的简单数据类型包括: 数字,字符串,true/false,null 和undefined. 其他所有值都是对象. 数组是对象,方法也是对象.属性值是除开undefined值以外的 ...

  3. Eloquent JavaScript #04# Objects and Arrays

    要点索引: JSON More ... 练习 1.补:js字符串的表达方式有三种: "" 和 '' 没什么区别,唯一区别在于 "" 中写 "要转义字符 ...

  4. [Javascript] Combine Objects with Object.assign and Lodash merge

    Learn how to use Object.assign to combine multiple objects together. This pattern is helpful when wr ...

  5. [Javascript] Create an Array concatAll method

    In addition to flat Arrays, programmers must often deal with nested Arrays. For example let's say we ...

  6. [Javascript] Create scrollable DOM elements with Greensock

    In this lesson, we will look at Greensock's Draggable API. We will implement a scrollable <div> ...

  7. Passing JavaScript Objects to Managed Code

    Silverlight If the target managed property or input parameter is strongly typed (that is, not typed ...

  8. JavaScript Objects in Detail

    JavaScript’s core—most often used and most fundamental—data type is the Object data type. JavaScript ...

  9. JavaScript原型

    prototype与_proto_ 对象的 prototype 属性的方法.属性为对象所属的那一"类"所共有.对象原型链通过 proto 属性向上寻找. 为 proto 指定 nu ...

随机推荐

  1. BZOJ.2428.[HAOI2006]均分数据(随机化贪心/模拟退火)

    题目链接 模拟退火: 模拟退火!每次随机一个位置加给sum[]最小的组. 参数真特么玄学啊..气的不想调了(其实就是想刷刷最优解) 如果用DP去算好像更准.. //832kb 428ms #inclu ...

  2. 理解onPause和onStop

    onPause 用于由一个Activity转到另一个Activity.设备进入休眠状态(屏幕锁住了).或者有dialog弹出时 onStop 用于不可见的Activity(有对话框弹出时,这时底下的a ...

  3. Node.js学习笔记(1) - Node.js简介

    近期在看一些Node.js的知识,看完后觉得,一些前面的东西忘记了,于是整理一下,方便自己查阅,也希望对学习Node.js的朋友有些帮助: 当然以下只是我个人的观点和理解,不喜勿喷,也望大神指教. 一 ...

  4. cat ,more ,less 命令的使用和差别

    cat命令功能用于显示整个文件的内容单独使用没有翻页功能因此常常和more命令搭配使用,cat命令还有就是将数个文件合并成一个文件的功能. more命令功能:让画面在显示满一页时暂停,此时可按空格健继 ...

  5. MYSQL 源代码学习

    http://ourmysql.com/ http://blog.chinaunix.net/uid-26896862-id-4009777.html

  6. DU 4609 3-idiots FFT

    题意还是比较好懂. 给出若干个木棍的长度,问这些木棍构成三角形的可能性. 那么公式很容易知道 就是这些木棍组成三角形的所有情况个数 除以 从n个木棍中取3个木棍的情况数量C(n, 3) 即可 但是很显 ...

  7. 开启PowerDesigner15工具栏上的被禁用掉的图标

    PowerDesigner 15 的版本,工具栏上的Inheritance图标默认是禁用的,如下图所示:

  8. python定位性能的工具

    参考: http://www.ibm.com/developerworks/cn/linux/l-cn-python-optim/ http://xianglong.me/article/analys ...

  9. 常用NFS mount选项介绍

    通过NFS挂接远程主机的文件系统时,使用一些不同的选现可以使得mount比较简单易用.这些选项可以在mount命令中使用,也可以在/etc/fstab和autofs中设定.  以下是NFS mount ...

  10. mq刷盘方式

    Broker 在收到Producer发送过来的消息后,会存入CommitLog对应的内存映射区中,见CommitLog类的putMessage方法.该方法执行OK后,会判断存储配置中刷盘模式:同步or ...