Hi All, This is a “Dynamic List- User Add Elements” question. I was directed here by Kresimir. My array and other aspects of code isn’t working like it’s supposed too. Please see attached image. @ivan @abuga @thecil @Malik. Please let me know what I need to correct I’ve copied the code word for word from my lenovo computer and I’m getting odd colors representing different tags and equal signs after loops and variables. Thanks for you all’s time and look forward to hearing back soon.
PART 1 - Data Structures: Objects and Arrays:
- Read the sub-chapter called The weresquirrel. What problems does this chapter introduce that cannot be solved with variable types such as strings or integers? The problem is that with just strings and integers, Jacques cannot store multiple values in a data structure that will be easily accessible.
- What variable type can be used in order to solve the problem of storing multiple values? Arrays.
- What are properties in Javascript? Properties are the values associated with a JavaScript object.
-
Which values do not have properties?
null
andundefined
. -
How can we access properties in a value (two ways)? The two main ways to access properties in JavaScript are with a dot and with square brackets (
value.x
andvalue[x]
) - What are methods? Properties that contain functions.
- What are objects? JavaScript object is a non-primitive data-type that allows you to store multiple collections of data
- What problem do objects solve that cannot be solved with other value types we’ve learned so far (such as integer, string, array, boolean etc)? * Objects may contain any combination of any primitive data-type as well as reference data-types whereas primitive data-types can only store values of a single data-type.
- How do you define an object?
let day1 = {
squirrel: false,
events: ["work", "touched tree", "pizza", "running"]
};
- What can you say about the mutability of Javascript objects? A mutable object is an object whose state can be modified after it is created.
PART 2 - Strings and their properties:
- Why can’t you add new properties to a string variable? Because primitive data-types such as string are immutable.
- What are rest parameters? A rest parameter is a parameter that actually allows us to input any amount of parameters as inputs in a function.
- (Feel free to skip the sub-chapter of Math object and Destructing) Ok.
-
What is serialization and what is a use case of serialization of data? Data serialization is the process whereby an object or data structure is translated into a format suitable for transferal over a network, or storage. To save data in a file or send it to another computer over
the network are examples of serialization of data use cases. - What is JSON? JavaScript Object Notation which is widely used as a data storage and communication format on the Web.
- What are the differences between JSON and the way programmers write objects in plain Javascript? That in JSON all property names have to be surrounded by double quotes, only simple data expressions are allowed—no function calls, bindings, or anything that involves actual computation and that comments are not allowed.
Pt.1:
- Having a data form that would account for a list of values within the “squirrel’s” daily actions and events in order to narrow down the root of the illness that results in transformations.
- data sets, i.e ARRAYS
- Expressions that are able to access some value.
- null & undefined.
- Either by a dot or by using square brackets; value.x || value[x].
- They are properties that contains functions of the value they belong to.
- They are arbitrary collections of properties; single values put into grouped values which are put into an array of log entries.
- They grasp values, while other bindings and properties may be holding onto those same values; they are more permanent but also mutable.
- Using braces, inside of the braces are a list of properties that are separated by commas, with each name followed by a colon and a value pertaining to it.
- They are able to be modified; you are able to change their properties causing a single object value to have different content at different times.
Pt.2:
- This type of value is immutable and cannot be changed once set.
- A function that is bound to an array containing all further arguments.
- —————
- Converting the data into a flat description used as a form of data storage.
- (JavaScript Object Notation) is a popular form of serialization format that is widely used for data storage and communication on the web, even in other languages that JavaScript.
- Only simple data expressions are allowed; no functions, bindings called or any form of computation, as well as any commentary within script.
Please copy paste your code here instead of sending screenshots. It will help immensely to check out your issues.
Thanks and regards.
A.Malik
- Read the sub-chapter called The weresquirrel. What problems does this chapter introduce that cannot be solved with variable types such as strings or integers?
Strings and integers are simple data types, however, in programming, we have to mostly deal with more complex tasks. For example in order to create even a simple database we need to group several values into a single value, such as presented in this chapter about weresquirrel. This might be resolved by using arrays and objects which provide us with the way to group values together.
- What variable type can be used in order to solve the problem of storing multiple values?
If these are conceptually identical values, we use arrays.
- What are properties in Javascript?
Property- is a parameter of the value that describes attributes associated with the data structure.
-
Which values do not have properties? Null and undefined values (non-values) can not have properties.
-
How can we access properties in a value (two ways)?
With dot or square brackets. Example: value.x and value[x]. When we use ‘value.x’ we fetch the property of value named “x”, and value[x] is the operation, which gives you back the property name(converted to string), associated with “x”.
- What are methods?
Methods literally are the properties that contain function values.
- What are objects?
An object is the arbitrary collection of named values(properties and methods). All JavaScript values except 5 primitives (string, number, boolean, null, undefined)are objects. JS basically is an object-oriented programming language.
- What problem do objects solve that cannot be solved with other value types we’ve learned so far (such as integer, string, array, boolean etc)?
The object can store a collection of data rather than just a single value, unlike for instance arrays that only hold a list of values.
- How do you define an object?
The object can be defined in the following 2 ways:
var car = new Object();
car.brand = “Ford”;
car.model = “Focus”;
car.year = 2011;
var car = {
brand: 'Ford',
model = 'Focus',
year = '2011',
};
10. What can you say about the mutability of Javascript objects?
Javascript objects are mutable. We can change their properties so that a single object value will have different content at different times. However, they are addressed by reference, not by value.
For let x = person; any change to ‘x’ will affect ‘person’ as well. But at the same time object with identical values are not considered to be identical in Javascript.
- Why can’t you add new properties to a string variable?
By default strings, numbers and booleans are not objects in JS(except if they are defined with a keyword “new”). Such values are immutable, unlike objects.
*2. *What are rest parameters?
Sometimes it is useful for a function to accept any number of arguments. To write such a function we add “…” before the last function’s parameter.
function max(...numbers){
}
When we call this function, the rest parameter is bound to an array containing all the rest of the arguments.
-
(Feel free to skip the sub-chapter of Math object and Destructing)
-
What is serialization and what is a use case of serialization of data?
Serialization of data means converting the data into a flat description. This is used to effectively save data in a file for later or to send it to another user.
- What is JSON?
JSON (JavaScript Object Notation) is a popular data serialization format, widely used for data storing and as a communication format on the Web.
- What are the differences between JSON and the way programmers write objects in plain Javascript?
The difference is that in JSON all property names have to be surrounded by double-quotes. Only simple data expressions are allowed. Comments are also not allowed.
{
“rain” : true,
“events” : [“dinner at home”, “cleaning”, “working”]
}
1. Read the sub-chapter called The weresquirrel. What problems does this chapter introduce that cannot be solved with variable types such as strings or integers?
A variable that can store multiple values.
2. What variable type can be used in order to solve the problem of storing multiple values?
An Array
3. What are properties in Javascript?
Javascript objects are containers for named values called properties.
4. Which values do not have properties?
Undefined and null
5. How can we access properties in a value (two ways)?
The two main ways to access a value’s property are with a dot and a square bracket.
. & [ ]
6. What are methods?
Methods are actions that can be performed on objects.
Methods are stored in properties as function definitions.
Methods are nothing more than properties that hold function values.
toUpperCase & toLowerCase are two examples.
7. What are objects?
Objects are able to contain many different datatypes.
An object is a piece of data that has its own properties and methods.
- A car has properties like weight and color, and methods like start and stop. -
8. What problem do objects solve that cannot be solved with other value types we’ve learned so far (such as integer, string, array, boolean etc)?
Objects are complex and each object may contain any combination of primitive data-types as well as reference data-types.
9. How do you define an object?
{
}
10. What can you say about the mutability of Javascript objects?
Primitive values such as numbers, string and booleans are immutable, meaning it’s not possible to change values of those types. Objects are more flexible; “causing a single
object value to have different content at different times.”
SECOND PART:
1. Why can’t you add new properties to a string variable?
A string is not an object, in other words you can’t add new properties to strings. They can’t be changed.
2. What are rest parameters?
Rest parameters allow for functions to accept any number of arguments. They are preceded by 3 dots before it’s name in a function definition.
3. (Feel free to skip the sub-chapter of Math object and Destructing)
4. What is serialisation and what is a use case of serialisation of data?
Serialisation is the conversion of data stored in memory into a simple string-like description of what this data is.
5. What is JSON?
Javascript Object Notation a popular serilisation format.
6. What are the differences between JSON and the way programmers write objects in plain Javascript?
The differences between JSON and the way programmers write objects in plain Javascript are:
- All property names must be surrounded by double quotes.
- Only simple data expressions are allowed - function calls, bindings, or anything that involves actual computation aren’t allowed.
- JSON doesn’t allow comments.
@Malik here is the code that I think matches with Ivan’s at the beginning of the lesson. The array is not appearing on the website and the equal sign after the variable is turning purple instead of blue to provide insight. Thanks for your response and help.
Great WebsiteMy favorite fruits
<html>
<head>
<title> Great Website </title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<h1> My favorite fruits </h1>
<ol id ="fruitlist">
</ol>
<script>
var fruits = ["apple","orange","banana","pineapple"];
var list = $("fruitlist");
$.each(fruits,function(index,value){
$("<li/>").text(value).appendTo(list);
});
console.log(fruits);
</script>
</body>
</html>
@malik it’s not showing the code when I copy it so tried to send it via email. Let me know if you got it.
Thanks!
- Read the sub-chapter called The weresquirrel. What problems does this chapter introduce that cannot be solved with variable types such as strings or integers?
- Since he has to put different events into a function to see what triggers the squirrel transformation, it is not possible to use strings since he needs to change the events day by day.
He needs to use objects which is not immutable.
- What variable type can be used in order to solve the problem of storing multiple values?
- Arrays can be used to store multiple values.
- What are properties in Javascript?
- Properties are characteristics (properties) of a value or object. It defines the structures of a value such as .length (how many letters) or index (what number from 0-x a value is at) for example.
- Which values do not have properties?
- Null and Undefined
- How can we access properties in a value (two ways)?
- With value.property and value[“property”]
- What are methods?
- Methods are like built in functions i JS used on objects, here is an example i made:
var MyFarm = {
Animal: "Chicken", //this is an object
Eggs: 19, //this is also an object
Laysegg: function() { //this is the Method for the objects
console.log(MyFarm.Animal + " " + "Lays" + " " + MyFarm.Eggs + " " + "eggs");
}
};
MyFarm.Laysegg();
—-> Chicken Lays 19 eggs
We can now change the eggs in the object or even the animal if we want and still get the same text write out every time we run the method.
- What are objects?
- Objects are any type of data that can be modified in the program. Strings, numbers and Boolean are not classified as objects as their values are immutable.
- What problem do objects solve that cannot be solved with other value types we’ve learned so far (such as integer, string, array, boolean etc)?
- Objects can have their value modified in the code, they also allow different types of values as objects.
- How do you define an object?
- Objects can be defined by using curly brackets
My Objects = {
object 1: ‘cat’
};
- What can you say about the mutability of Javascript objects?
- Objects are mutable meaning they can be modified in the code by using Methods. You can add and remove a value etc.
SECOND PART:
- Why can’t you add new properties to a string variable?
- A string is an immutable value meaning their properties stays the same and can’t be modified.
- What are rest parameters?
- Rest parameters works like placeholders for arguments in a function. There is no maximum on the amounts of arguments that can be placed into the function.
The parameter when called needs to start with 3 dots followed by the parameter in the function, it must be the last parameter in the function.
The rest parameter is then represented as an array.
- (Feel free to skip the sub-chapter of Math object and Destructing)
- okay
- What is serialisation and what is a use case of serialisation of data?
- Serilazation is the way of storing data in plain text, a popular seralization format is called JSON. This format lets you send the objects and arrays on the web, since they without the JSON format only grasps the value from the computers memory.
- What is JSON?
- JSON stands for JavaScript Object Notation is a type of serilazation format that lets you flatten the program into readable text, it has to have double quotation when it comes to properties and can’t contain any comments, actual computation or functions.
- What are the differences between JSON and the way programmers write objects in plain Javascript?
- JSON must write properties with double quotation marks.
let Mypets = {
“Pet1”: “cat”,
“Pet2”: “dog”,
“Pet 3: “parrot”
};
When writing properties in plain JavaScript there are no double quotations for the properties.
In JSON, you can’t include any bindings, computation or comments.
-
Strings and integers can only capture single variables at a time, so we need to use a data structure to capture more than one value at once.
-
An array is used to store multiple values at once.
-
They are characteristics of the values in a data set.
-
null and undefined.
-
we access properties with either a dot or with square brackets.
-
A method is a property that holds a function
-
Arbitrary collections of properties
-
Objects can store values of different types such integers, booleans, strings, and arrays.
-
Using braces as an expression {x,y}
-
Objects in javascript can be modified (are mutible), whereas numbers, strings, and Booleans cannot.
-
Because a string is an immutable variable, so it doesn’t allow for new properties to be set on them.
-
The rest parameter is bound to an array containing all further arguments.
-
Coolsies.
-
Serializing data means it is converted into a flat description. This means it can be transferred over the data network.
-
JSON stands for JavaScript Object Notation. It is a data storage and communication format on the web.
-
All property names have to be surrounded by double quotes, and only simple data expressions are allowed- no function calls, bindings, or actual computation allowed.
Please use the Pre-formatted styling for your code when posting on the forum. This ensures you code is in a code block.
When you are selecting an element through their ID, make sure to add the # symbol before it.
var list = $("#fruitlist");
//This way
This will solve the issue.
Hope this helps. Have a nice day.
Part one:
-
Jaques needs to store multiple pieces of info
-
Arrays and/or objects
-
Properties work with the value sort of like a function
-
null, undefined…
-
You can access them by either using a dot: . or square brackets: [ ]
-
Methods are the properties that hold onto function values
-
It is a list of properties
-
You can change info in one object using a piece of code
-
You define them as so : let yourObject = {
info…
}
just like variable but with curly braces -
It is complicated.
Part two:
-
Variables can not be changed because they are immutable unlike objects.
-
Rest Parameters take the next arguments and put them into an array.
-
Skip
-
To serialize is to make a flat description of binary code, and is used to store more data
-
JSON stands for Javascript Object Notation it is used for data storage ect.
-
You have to use “” for all properties, no calling functions ect.
- What problems does this chapter introduce that cannot be solved with variable types such as strings or integers?
Logging multiple values within a variable
- What variable type can be used in order to solve the problem of storing multiple values?
Arrays
- What are properties in Javascript?
The properties (attributes & characteristics) values posess
- Which values do not have properties?
Null and undefined
- How can we access properties in a value (two ways)?
value.x (the word after the dot is the literal name of the property)
or value[x] (tries to evaluate the expression and uses the result as the name)
- What are methods?
Properties that contain functions
.push method adds values at the end of an array while the .pop method does the opposite.
- What are objects?
Values of the type object are random collections of properties
- What problem do objects solve that cannot be solved with other value types we’ve learned so far (such as integer, string, array, boolean etc)?
The ability to store lists of values and a boolean to determine if its true or false within a variable.
- How do you define an object?
let day1 = {
sunnyDay: false,
events: [“rain”, “thunder”, “clouds”] }
Using braces as an expression.
- What can you say about the mutability of Javascript objects?
Object properties can be modified to be different at different times whereas booleans, strings and number values discussed earlier cannot be changed.
- Why can’t you add new properties to a string variable?
Stings can be combined to create new values but specific strings can never be changed. These variables do not actually store properties.
- What are rest parameters?
the spread operator can copy elements of an array into another while the rest operator allows a function to take in the rest or any number of parameters into operation
-
What is serialisation and what is a use case of serialisation of data?
-
Data is converted into a flat description (JSON)
-
What is JSON?
Javascript Object Notation (JSON) is used to store and communicate data even in other langauages than JS.
- What are the differences between JSON and the way programmers write objects in plain Javascript?
All property names must be surrounded by double quotes, no comments or any actual computation like function calls are allowed.
- Variable types such as strings and integrers are only able to hold a single type of data. The solution? It requires a varaible that can store multiple values.
- Arrays and objects.
- Properties are expressions that access a property of some value.
- Null and undefined do not have properties.
- Value.x // value[x]
- Methods are properties that hold function values. These are special kinds of functions that only work on the value they belong to.
7.Objects are considered a collection of properties, inside object the user can store different value types. - Objects can store values of different types as integers, booleans, strings and arrays.
- Eg: “car” = {calor: “red”, type: “SUV”}
- Mutability of Javascript objects menas that the values they contained can be changed.
Second Part.
- Because string variable are immutable.
- It is the use of any number of arguments in a function.
- Ok. In coding 1+1= 3. LOL
- Is the process whereby an object or data structure is translated into a format suitable for transfer over a network or storage” // “convert into a flat description.
- JavaScript Object Notation is a serialisation format. It is widely used as a data storage and communication format on the Web.
- Properties should also be written inside double quotes. JSON only allow simple values expression like strings, numbers, arrays and booleans. “So no function calls, bindings, or anything that involves actual computation.
Part 1:
- To identify reason for strange anomaly, there is a need to structure data and to have possibility to store multiple values for variables.
- Array
- Elements in an array that provide information about values.
- null and undefined
- Using dot or square brackets. E.g. value.x or value[x]
- Properties that contain functions are generally called methods
- Arbitrary collections of properties
- You can change their properties, causing a single object value to have different content at different times.
- Objects allow us to group values—including other objects—to build more complex structures.
- Objects are mutable, we can change their properties causing a single object value to have different contantent at different time.
Part 2:
- They are not objects and dont store properties.
- Functions last parameter with three dot notation put before the parameter. It enables to accept any number of argument.
-
- Serialisation is flatenning of data in order to send it over to different computers and make it easy readable.
- It is widely used as a data storage and communication format on the Web, even in languages other than JavaScript.
- All property names have to be surrounded by double quotes, and only simple data expressions are allowed—no function calls, bindings, or anything that involves actual computation. Comments are not allowed in JSON.
Part one
-
Sometimes you need to store more than one value in a variable and also be able to call on each value individually.
-
Arrays.
-
Properties are values that are associated with an object in JavaScript. The length property of an array will tell us how many elements it has and the length property of a string will tell us how many characters it has. Each element of an array is also considered a property, and the property name of an element is that element’s index.
-
Null and undefined.
-
With a period, for example string.length
Or with square brackets, for example array[2] -
Methods are properties that contain functions.
-
An object is a collection of properties.
-
Properties of objects can be changed so they have different content at different times.
-
Like creating other bindings but you open curly braces and separate properties with commas. Property names and their values are separated by colons.
let object = {
propertyOneName: value,
propertyTwoName: value
};
- Normal bindings can’t actually have their values changed. You can only manipulate them and perform operations on them to make them point to different values. Objects are mutable. You can change the contents of an object and if you have more than one binding referencing that object, it will be changed for all of those bindings.
Part two
-
Because it is not an object. Strings are immutable. Their properties are built in and accessing them will always return the same result on all strings of that same value.
-
When a function needs to be able to accept any number of parameters, you give it a rest parameter. When the function is called, the rest parameter is bound to an array containing all arguments given.
-
Data serialisation takes an object in memory and converts it into a flat description. This is useful for sending the data elsewhere over a network.
-
JavaScript Object Notation. It is a data serialisation format.
-
In JSON, property names have to be in double quotes. There can be no function calls, bindings, or anything that involves computation, and comments are not allowed.
1.- Well the issue is that by using strings and integers you cannot be precise with the data or your would have to define everthing to the point of having too much data that is not necesary - Jacques needs to access the information directly listed to cross match in the future.
2.- An “ARRAY” in Javascript lets you store a list of values and retrive them by indexes that start from 0,1,2 etc.
3.- Properties are charaters that define a value within Javascript for example if you want to show the length of a string you use myString.lenght(x).
4.- “null” and “undefined”, these are nonvalues.
5.- By “value.x” and “value[x]”
6.- They are properties that contain functions
7.- These are value types that are arbitrary collections of properties (I think of a list like of array)
8.- Please consider that I looked for help on this one, got a bit confussed - “Objects are special as they are able to hold as many different data types as we need”
9.- You define them within “{}” as any other variable
10.- These can be changed or used in different ways due to the fact that they are collections of properties - ObjectA is not the same as ObjectB, they have the same identity if we give them values that are the same.