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. PHP cURL中CURLOPT_CONNECTTIMEOUT和CURLOPT_TIMEOUT的区别

    CURLOPT_CONNECTTIMEOUT用来告诉PHP脚本在成功连接服务器前等待多久(连接成功之后就会开始缓冲输出),这个参数是为了应对目标服务器的过载,下线,或者崩溃等可能状况: CURLOPT ...

  2. luoguP3871 [TJOI2010]中位数

    题目链接 luoguP3871 [TJOI2010]中位数 题解 平衡树 代码 #include<vector> #include<cstdio> #include<cs ...

  3. wdcp(WDlinux Control Panel) 快速安装RPM包,lanmp一件安装

    lanmp一键安装包是wdlinux官网2010年开始推出的lamp,lnmp,lnamp(apache,nginx,php,mysql,zend,eAccelerator,pureftpd)应用环境 ...

  4. Sql server 存储过程基础语法

    一.定义变量 --简单赋值 declare @a int print @a --使用select语句赋值 declare @user1 nvarchar() select @user1='张三' pr ...

  5. An ac a day,keep wa away

    zoj 初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 1334 ...

  6. Codeforces Round #288 (Div. 2) C. Anya and Ghosts 模拟 贪心

    C. Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. C# 7.0特性与vs2017

    下面是关于在C#7.0语言中计划功能的说明.其中大部分功能在Visual Studio “15” Preview 4中能运行.现在是最好的试用时期,请记录下你们的想法. C#7.0语言增加了许多的新功 ...

  8. SMB协议概述

    一.概述 SMB(Server Message Block)是由微软开发的一种软件程序级的网络传输协议,主要用来使得一个网络上的计算机共享计文件.打印机.串行端口和通讯等资源.它也提供认证的进行进程间 ...

  9. 一个java高级工程师的进阶之路【转】

    宏观方面 一. JAVA.要想成为JAVA(高级)工程师肯定要学习JAVA.一般的程序员或许只需知道一些JAVA的语法结构就可以应付了.但要成为JAVA(高级) 工程师,您要对JAVA做比较深入的研究 ...

  10. TPS70345 (ACTIVE) 双路输出低压降 (LDO) 稳压器

    The TPS703xx family of devices is designed to provide a complete power management solution for TI DS ...