Javascript
Provide code to create a custom object named pokerCard containing the suit property with a value of "Spades" and a rank property with a value of "King".
Solution:
We can create a custom object in following two ways:
1. Creating it as an object literal:
A custom object can be created by an object literal by storing the properties of the object within a comma-separated list of name:value pairs enclosed within a set of curly braces.
The general syntax of the object literal is
var objName = { name1: value1, name2: value2,
...
};
where objName is the name of the object, name1, name2, and so on are the names associated with that object, and value1, value2, and so on are the values assigned to those names.
Code to create a custom object named pokerCard containing the suit property with a value of "Spades" and a rank property with a value of "King":
var card1 = { title: "pokerCard", suit: "Spades", rank: King};
2. Using an object constructor:
To create such object classes, you apply a function known as an object constructor or a constructor that defines the properties and methods associated with the object type. A specific object that is based on an object class is known as an object instance or instance. Creating an object instance based on an object class is known as instantiating an object.
Code to create a custom object named pokerCard containing the suit property with a value of "Spades" and a rank property with a value of "King":
The constructor function for an object class of poker cards might appear as follows:
function pokerCard(cardSuit, cardRank) {
this.suit = cardSuit;
this.rank = cardRank;
this.rankValue = null;
this.showCard() function() {
return "Your card is a " + this.rank + " of " + this.suit;
}
}
Once the constructor function for the object class is defined, instances of the object are created with the command
var objInstance = new objClass(parameters);
where objInstance is a specific instance of the object, objClass is the object class as defined by the constructor function, and parameters are the values of any parameters included in the constructor function. Thus, the following code creates two instances of the class of pokerCard objects, one for the king of hearts and the other for the seven of spades:
var card1 = new pokerCard("Spades", "King");
card1.rankValue = 13;
Please give thumbsup, if you like it. Thanks.
Javascript Provide code to create a custom object named pokerCard containing the suit property with a...
Javascript Provide the code to add the custom dropRank() method to the pokerCard object that changes the value of the rank property to "Queen". (Hint: Create the dropRank() function and use the this keyword to reference the current object.)
Javascript Provide the code to add the custom dropRank() method to the pokerCard object that changes the value of the rank property to "Queen". (Hint: Create the dropRank() function and use the this keyword to reference the current object.)
code 3 different ways to insert a property-value pairing into a javascript object where the object name is Seneca, the property name is coursecode and the value is WEB322
create a javascript function named bbqFood that takes in an object and returns an array. The input object will have strings naming party foods as the key and the numbers of people that each key will feed as its values. return an array containing all of the keys whose values are greater than 10, menaing it will feed more than 10 people. example bbqfood(['taco':15, 'hamburger':6,'pasta':42,'fruit':23}) must return ['taco','pasta','fruit']
code a statement that sets the value of the Age property of an Account object named account to the value in a variable named newAge.
1. Provide code to create a selection list named orderDay containing the values and option text SAT and SUN placed in the Weekend option group, and the option text MON, TUE, WED, THU, and FRI placed in the Weekday option group. 2. Provide code to create two radio buttons for the compType field with the values PC and Mac. Make PC the default value. 3. Kelsey has written the following code to create a data field for users to select...
In java please Create an immutable class named Card implementing the Comparable interface that will represent a card, have a suit: diamonds - lowest, clubs, hearts, spades - highest) and a rank ( 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A). The class must have a constructor provided with a suit and rank, and the following methods: toString(), getSuit(), getRank(), print(). Create a static method that will randomly generate a card. A card is less...
Create a JavaScript function named display_data that has two parameters. The first parameter will be a String containing a JSON blob like the function in part 1 returns. The second parameter will be a boolean. Start by using the JSON library to convert the first parameter into a usable JavaScript Object. Next get the HTML element whose id is "data". This HTML element is a div. If the second parameter is equal to true , write the value associated with...
Objectives: Develop an object-oriented program Develop a test program that is separate from the class under development ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Define a class where one object of the class represents a playing card. If you are not familiar with a deck of playing cards, you will need to spend some time understanding the rank and suit that is on each playing card. You can look it up in wikipedia and see an image of the whole deck of 52 playing cards here:...
Javascript Object question: Write a function named "indexed_kvs" that doesn't take any parameters and returns a new key-value store containing the integers from 0 to 30 as values each stored at a key which is a string containing the digits of the integer. For example the key-value "0":0 will be in your returned key-value store (include both 0 and 30 in your list)