# Alchemy University 学习教程,JS第一大块:Data Storage (3) **Published by:** [andrecronje](https://paragraph.com/@nicholastse/) **Published on:** 2023-01-01 **URL:** https://paragraph.com/@nicholastse/alchemy-university-js-data-storage-3 ## Content 估值102亿融资5.45亿的Alchemy 项目,大学每周任务逐步开始。持有大学生早期卡的地址可以进入以下官网,开始大学生活: 这一期我们学习 Objects (对象): 1: Pizza Order (披萨订单) 查看要求,创建一个关于披萨订单的对象: 输入:( go to build 可以改成自己喜欢的句子) const order = { pizzas: 2, extraCheese: true, deliveryInstructions: "go to build" }; module.exports = order; 点击运算。 2: How Many Pizzas 查看要求,需要算出披萨订单的数量: 输入: function numberOfPizzas(order) { return order.pizzas; } module.exports = numberOfPizzas; 点击运算。 3: Many Orders 查看要求,给定一组披萨订单,需要求出披萨订单的总和: 输入: function numberOfPizzas(orders) { let s = 0; for(let i = 0; i < orders.length; i++) { s = s + orders[i].pizzas; } return s; } module.exports = numberOfPizzas; 点击运行。 4: Typed Orders 查看要求,我们需要创建不同类型的订单: 输入: const ORDER_TYPES = { PIZZA: 0, SALAD: 1, FRIES: 2 } module.exports = ORDER_TYPES; 点击运行。 5: Add By Type 按类型求和 查看要求,在多种订单,只找到披萨的订单并求总订单量: 在这里要注意,输入的是这个文件: 输入: const ORDER_TYPES = require('./orderTypes'); function numberOfPizzas(orders) { let s = 0; for(let i = 0; i < orders.length; i++) { if (orders[i].type === ORDER_TYPES.PIZZA) { s = s + orders[i].pizzas; } } return s; } module.exports = numberOfPizzas; 点击运行。 6: Object Keys 对象键 查看要求,给定一个对象,需要找到它对应的数量,如,披萨--5 ,找到的就是 5 。 输入: function numberOfKeys(object) { let n = 0; for(let key in object) { n = n + 1; } return n; } module.exports = numberOfKeys; 点击运行。 7: Secret Key 秘钥 查看要求,需要删除掉秘钥: 输入: function removeSecret(object) { delete object.secret } module.exports = removeSecret; 点击运行。 以上 JS的 Data Storage 一节已经完成,下一篇开始我们的练习 2 。 未完待续…… 了解更多,请关注作者:https://twitter.com/bitc2024 ## Publication Information - [andrecronje](https://paragraph.com/@nicholastse/): Publication homepage - [All Posts](https://paragraph.com/@nicholastse/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@nicholastse): Subscribe to updates - [Twitter](https://twitter.com/kobe80318935): Follow on Twitter