[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 ...
随机推荐
- springboot配置多数据源mongodb
参考大佬的文章 https://juejin.im/entry/5ab304dd51882555825241b3
- Hdu4903 The only survival
The only survival Time Limit: 40000/20000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Ot ...
- Sublime Text2 默认语言(windows/unix)设置,Sublime插件大全
Sublime默认系统语言设置 Sublime Text 2默认使用的就是UTF8,这个UTF8模式使用的是不带BOM的,如果要修改这个配置,到Perference->Settings-User ...
- java多线程技术之八(锁机制)
Lock是java.util.concurrent.locks包下的接口,Lock 实现提供了比使用synchronized 方法和语句可获得的更广泛的锁定操作,它能以更优雅的方式处理线程同步问题,我 ...
- Vue 生命周期方法
一.Vue 生命周期 Vue的生命周期即是实例从创建到销毁的一个过程.之前在学习Vue的时候,看过官网的教程,但是经常用到的是mounted,所以对其他生命周期方法不是很熟悉,这里有空做个总结,也方便 ...
- [OpenGL]纹理贴图实现 总结
实现步骤 第一步:设置所需要的OpenGL环境 设置上下文环境 删除已经存在的渲染的缓存 设置颜色缓存 设置帧缓存 清除缓存 设置窗口大小 开启功能 编译shander 使用program 获取sha ...
- Codeforces Round #256 (Div. 2) C. Painting Fence
C. Painting Fence Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Ch ...
- Codeforces Round #280 (Div. 2) A. Vanya and Cubes 水题
A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- javascript小记-闭包理解
这几天也在看一些javascript的知识,算是对以往的一个复习,现小记一下,方便以后查询. 相信大家在研究javascript的高级特性的时候,肯定会遇到闭包的概念,自己在各种复习资料中,也发现了不 ...
- Eclipse upper case/lower case
How do I make a lower case string in Eclipse to be upper case?Using Eclipse, I want to select a stri ...