[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:
- name: “Nick Walsh”, skillz: “magnification burn”, station: 2
- name: “Drew Barontini”, skillz: “uppercut launch”, station: 3
- name: “Christine Wong”, skillz: “bomb defusing”, station: 1
Each added ranger object should become its own property within lighthouseRock, specifically ranger1, ranger2, 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 location, name, skillz, 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的更多相关文章
- [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 ...
- Javascript笔记--Objects
Javascript的简单数据类型包括: 数字,字符串,true/false,null 和undefined. 其他所有值都是对象. 数组是对象,方法也是对象.属性值是除开undefined值以外的 ...
- Eloquent JavaScript #04# Objects and Arrays
要点索引: JSON More ... 练习 1.补:js字符串的表达方式有三种: "" 和 '' 没什么区别,唯一区别在于 "" 中写 "要转义字符 ...
- [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 ...
- [Javascript] Create an Array concatAll method
In addition to flat Arrays, programmers must often deal with nested Arrays. For example let's say we ...
- [Javascript] Create scrollable DOM elements with Greensock
In this lesson, we will look at Greensock's Draggable API. We will implement a scrollable <div> ...
- Passing JavaScript Objects to Managed Code
Silverlight If the target managed property or input parameter is strongly typed (that is, not typed ...
- JavaScript Objects in Detail
JavaScript’s core—most often used and most fundamental—data type is the Object data type. JavaScript ...
- JavaScript原型
prototype与_proto_ 对象的 prototype 属性的方法.属性为对象所属的那一"类"所共有.对象原型链通过 proto 属性向上寻找. 为 proto 指定 nu ...
随机推荐
- Java实现杨辉三角形
Java实现杨辉三角形 一.源代码:YFTriangle.java package cn.com.zfc.day009; import java.util.Scanner; /** * 打印杨辉三角形 ...
- [BZOJ1815&BZOJ1488]有色图/图的同构(Polya定理)
由于有很多本质相同的重复置换,我们先枚举各种长度的点循环分别有多少个,这个暴搜的复杂度不大,n=53时也只有3e5左右.对于每种搜索方案可以轻易求出它所代表的置换具体有多少个. 但我们搜索的是点置换组 ...
- BZOJ 4066 简单题(KD树)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4066 [题目大意] 要求维护矩阵内格子加点和矩阵查询 [题解] 往KD树上加权值点,支 ...
- 使用jQuery的插件qrcode生成二维码(静态+动态生成)及常见问题解决方法
一.简介 1.说明 qrcode其实是通过使用jQuery实现图形渲染,画图,支持canvas(HTML5)和table两种方式,您可以到https://github.com/jeromeetienn ...
- HDU 5150 Sum Sum Sum 素数
Sum Sum Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- (转,记录用)jQuery页面加载初始化的3种方法
jQuery 页面加载初始化的方法有3种 ,页面在加载的时候都会执行脚本,应该没什么区别,主要看习惯吧,本人觉得第二种方法最好,比较简洁. 第一种: $(document).ready(functio ...
- ProtoBuffer使用笔记
ProtoBuffer是由谷歌研发的对象序列化和反序列化的开源工具,ProtoBuffer和Xml类似,都是数据描述工具,后者使用更为广泛,前者Google内部使用且具有更高的效率.该工具安装和使用都 ...
- 读书笔记-APUE第三版-(8)进程控制
进程ID 每一个进程都有一个唯一的进程ID.几个特殊进程: 0号进程是内核进程,一般是调度进程swapper. 1号进程init,是用户进程(以root权限执行/sbin/init),负责初始化. 几 ...
- 进程内COM与进程外COM
1.进程内和进程外Com COM/DCOM 组件可以在DLL 或EXE 文档中实现. 其中在 DLL 中实现的COM/DCOM组件称为 In-Process Server,因为这些组件是加载到使用它们 ...
- 使用web.xml方式加载Spring时,获取Spring context的两种方式
使用web.xml方式加载Spring时,获取Spring context的两种方式: 1.servlet方式加载时: [web.xml] <servlet> <servlet-na ...