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. [BZOJ4699]树上的最短路(最短路+线段树)

    https://www.cnblogs.com/Gloid/p/10273902.html 这篇文章已经从头到尾讲的非常清楚了,几乎没有什么需要补充的内容. 首先$O(n\log^2 n)$的做法比较 ...

  2. VC被控制时关闭极域电子教室、破解联想硬盘保护系统密码(上)

    <[原]关于VC运行时关闭极域电子教室的改进方法> 本文将讲资料和方法,具体实现和破解联想硬盘保护系统密码在(下)中,有关破解联想硬盘保护系统(删除它)的方法很简单,用硬盘保护卡克星就可以 ...

  3. PAT甲级1127. ZigZagging on a Tree

    PAT甲级1127. ZigZagging on a Tree 题意: 假设二叉树中的所有键都是不同的正整数.一个唯一的二叉树可以通过给定的一对后序和顺序遍历序列来确定.这是一个简单的标准程序,可以按 ...

  4. IO流-复制多极文件夹(递归实现)

    package com.io.test; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import ...

  5. windows命令行快捷操作

    net use \\ip\ipc$ " " /user:" " 建立IPC空链接 net use \\ip\ipc$ "密码" /user: ...

  6. SET XACT_ABORT ON 数据库事务

    转载:http://www.cnblogs.com/rob0121/articles/2320932.html SET XACT_ABORT ON SET XACT_ABORT ON分为两种: 1.总 ...

  7. hibernate一级缓存,二级缓存和查询缓存

    一级缓存 (必然存在)  session里共享缓存,伴随session的生命周期存在和消亡:   1. load查询实体支持一级缓存 2. get查询实体对象也支持 3. save保存的实体对象会缓存 ...

  8. 报错:对一个或多个实体的验证失败。有关详细信息,请参阅“EntityValidationErrors”属性

    当使用Entity Framework,并且把领域模型的某个字段设置成不能为null,但在保存.更新的时候,如果领域模型的该字段为null了,就会报如上错误. 解决方法:给领域模型不能为null的字段 ...

  9. SHP文件合并

    ArcGIS中合并SHP文件是一个常用的操作,下面简要讲解一下如何合并. 使用ArcGIS Tool Box(ArcGIS工具箱)中的Data Management Tools-->Genera ...

  10. Selenium2+python自动化53-unittest批量执行(discover)

    前言 我们在写用例的时候,单个脚本的用例好执行,那么多个脚本的时候,如何批量执行呢?这时候就需要用到unittet里面的discover方法来加载用例了. 加载用例后,用unittest里面的Text ...