Skip to content
Akin C edited this page Mar 1, 2019 · 6 revisions

Welcome to the Javascript-operator-in- wiki!

This repository is part of a larger project!

◀️ PREVIOUS PROJECT| NEXT PROJECT ▶️


The operator in in Javascript should offer the possibility to verify an element`s existence e.g. in an array, object or instance. Code snippets for those named examples should follow now.

1. Array

var myArray = ["cat", "dog", "ape"];

/*
 0 is the index number in which cat exists.
 Next is the "in" operator
 "myArray" is the variable name in which the search is done.
*/
if(0 in myArray === true)
{
    alert("cat does exist")
}

To verify an element in an array, a specific index number would be needed. This should be not the case in the two following examples Object and Instance .



2. Object

var myObject = 
{
    anAttribute: 42
}

//Outputs true
alert("anAttribute" in myObject);

The verification would be done with a string value as the property/attribute which should be prompted in an object. This should be the same in the example Instance .



2. Instance

function myClass()
{
    this.myProperty = "A property";
}

var myInstance = new myClass();

//Outputs true
alert("myProperty" in myInstance);

A request of myProperty in myClass would be false as output.


Content

The user interaction part could look like the content as seen below by starting "index.html" in a web browser and interacting with its features.

ERROR: No image found!

  • Header "Info" contains the information about the formular "(X + Y + Z) * n = R".

  • Header "Task" contains the calculated value and three radio buttons. One of the values "X", "Y" and "Z" was deleted and the task of the user is to find/guess which of these three values.

Solutions

The table contains the calculated result with the specific value n and a deleted value "X", "Y" or "Z".

Deleted Value Value of n Calculated Result
X ; Y ; Z 1 37 ; 51 ; 86
X ; Y ; Z 2 74 ; 102; 172
X ; Y ; Z 3 111; 153; 258
X ; Y ; Z 4 148; 204; 344
X ; Y ; Z 5 185; 255; 430

To use the project just download the files and execute "index.html". Note that all files(folder "wiki_images" excluded) should be placed in the same folder so that the functionality of the code is guaranteed.

Clone this wiki locally