• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ironhack-labs/lab-javascript-clue: An exercise to practice JavaScript objects an ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

ironhack-labs/lab-javascript-clue

开源软件地址:

https://github.com/ironhack-labs/lab-javascript-clue

开源编程语言:

JavaScript 95.6%

开源软件介绍:

logo_ironhack_blue 7

LAB | JS Clue - Mixing objects and arrays

Do you remember the classic detective board game Clue? It was a very popular game in the 90's.

The plot starts with the death of Mr. Boddy, the very wealthy owner of Tudor Manor. He was killed under highly suspicious circumstances, and it's the player's mission to uncover which suspect murdered him, what weapon was used, and in which room of the mansion the crime took place.

When playing Clue, these three details are represented by a suspect card, a weapon card and a room card that are kept hidden in an envelope for the duration of the game. By progressively revealing the remaining cards, the players can infer which are the three cards that are hidden. When a player is confident that they know the solution to the mystery, they will try to reveal it. If a player guesses correctly, they win the game.

Requirements

  • Fork this repo
  • Clone this repo

Submission

  • Upon completion, run the following commands:
git add .
git commit -m "done"
git push origin master
  • Create a Pull Request so that your TAs can check your work.

Instructions

You will be working in the src/clue.js file, which is already loaded in the index.html file.

To run the JavaScript code, open the index.html file using the Live Server VSCode extension.

To see the output of your JavaScript code, open the Console in the Developer Tools.



Note about tests

This LAB is equipped with unit tests to provide automated feedback on your lab progress.

After completing the basic iterations, go to the "Test Your Code" section at the bottom. There you'll be asked to install the testing dependencies and run the tests to check how many tests your code is passing. Once you run the tests, correct your code to pass the failing tests.



Iteration 1: Create the cards

Clue has three different card types: suspects, rooms, and weapons.

Let's create an array for every card type. These arrays should be named suspectsArray, weaponsArray, roomsArray. Each array will contain objects, where each object represents one card.

All of the information you need about suspects, rooms, and weapons can be found on the DATA.md file.

Suggestion: Copy this data into the clue.js file and model it into objects nested inside your cards arrays. This is a great chance for you to experiment with IDE shortcuts, multiple-line selection, find and replace, and other great features that VS Code provides.


Suspects

All of six possible suspects in Clue have a first name, last name, occupation, age, description, image and color.

To complete this iteration, you should have an array that looks something like the following:

const suspectsArray = [
  {
    firstName: 'Jacob',
    lastName: 'Green',
    occupation: 'Entrepreneur'
    // ...
  }
  // ...
];

Weapons

There are a total of nine weapons. Each of them has a different name and weight.


Rooms

The game board represents the blueprints of the mansion and features fifteen different rooms. Each room will only have a name.


Iteration 2: Create the mystery

At the beginning of the game, players shuffle each of the card stacks to create a combination of suspect, weapon and room. This will be the mystery to solve.


Random selector

Declare a function named selectRandom to randomly select one element from a card stack. The function should expect an array as an argument, and should return a random element from the array.


Create the mystery

Declare a function named pickMystery that takes no arguments and returns an object with three properties: suspect, weapon and room, each holding as a value a card of that specific type. You can get a random card of each type by calling selectRandom on each card stack.


Iteration 3: Reveal the mystery

At last, we are ready to reveal the mystery.

Declare a function named revealMystery that receives an envelope object (with the shape of the object returned by pickMystery) as the single argument, and returns a reveal message in the following format:

<FIRST NAME> <LAST NAME> killed Mr. Boddy using the <WEAPON> in the <ROOM>!


Test Your Code

We will be working with automated tests again!

Please, open your terminal, change directories into the root of the lab, and run npm install to install the test runner. Now, you can run the npm run test:watch command to run automated tests in watch mode. Open the resulting lab-solution.html file with the "Live Server" VSCode extension to always see the most up-to-date test results.

Hint:

$ cd lab-javascript-clue
$ npm install
$ npm run test:watch

The test requirements (tests/clue.spec.js) will guide you in solving the remaining test requirements.


Extra Resources

Happy coding!


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap