From 630a9db9a420d28744848416f54e58d770f00d49 Mon Sep 17 00:00:00 2001 From: SOURAV GHOSH <153526688+SOURAVGHOSH123@users.noreply.github.com> Date: Sun, 2 Jun 2024 01:01:56 +0530 Subject: [PATCH] Update playground.js --- playground.js | 57 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/playground.js b/playground.js index 1e140ac..018fce0 100644 --- a/playground.js +++ b/playground.js @@ -1,15 +1,50 @@ -/* -// Metacrafters - Beginning Javascript -// -// This is a javascript playground for testing your javascript code! -// When you are ready to test, simply right click and select "Run Code" -// to see the result print below. If you have more then one snippet of code, -// you can highlight the code you want to test, and then right click and select "Run Code" +/* +Assessment Requirements +1. Create a variable that can hold a number of NFT's. What type of variable might this be? +2. Create an object inside your mintNFT function that will hold the metadata for your NFTs. + The metadata values will be passed to the function as parameters. When the NFT is ready, + you will store it in the variable you created in step 1 +3. Your listNFTs() function will print all of your NFTs metadata to the console (i.e. console.log("Name: " + someNFT.name)) +4. For good measure, getTotalSupply() should return the number of NFT's you have created */ -// Enter your code below this line +// create a variable to hold your NFT's +const NFTs = []; +// this function will take in some values as parameters, create an +// NFT object using the parameters passed to it for its metadata, +// and store it in the variable above. +function mintNFT (_name,_eyecolor,_shirttype,_bling) { + const NFT= { + "name" : _name, + "eyecolor": _eyecolor, + "shirttype": _shirttype, + "bling": _bling + } + NFTs.push(NFT); + console.log("Name: " + _name); +} + +// create a "loop" that will go through an "array" of NFT's +// and print their metadata with console.log() +function listNFTs () { + for (let i = 0; i < NFTs.length; i++) { + console.log("\nid: \t\t"+ (i+1)); + console.log("name: \t\t" + NFTs[i].name); + console.log("eyecolor: \t" + NFTs[i].eyecolor); + console.log("Shirt Type: \t" + NFTs[i].shirttype); + console.log("Bling: \t\t" + NFTs[i].bling); + } +} -// Code example -for(var i=1; i<=5; i++) { - console.log(i); +// print the total number of NFTs we have minted to the console +function getTotalSupply() { + console.log(NFTs.length); } + +// call your functions below this line +mintNFT("sourav","blue","normal","gold chain"); +mintNFT("soumya","red","design","gold watch"); +mintNFT("suman","white","smoothy","gold car"); +mintNFT("tapash","green","stylish","gold bike"); +listNFTs(); +getTotalSupply();