Skip to content
Akin C edited this page Aug 29, 2019 · 11 revisions

Welcome to the Javascript-storing-private-data- wiki!

This repository is part of a larger project!

◀️ PREVIOUS PROJECT| NEXT PROJECT ▶️


In other highlevel programming languages(like C++) information hiding is often a standard possibility. In javascript information hiding could be done by using closure.

A class structure seen in the next picture

ERROR: No image found!

could be done as follows:

function myClass()
{
    // Private member variable
    var myAttribute = 0;
    
    
    // First method
    this.setAttribute = function(attribute)
    {
        myAttribute = attribute;
    }
    
    // Second method
    this.getAttribute = function()
    {
        return myAttribute;
    }
    
}


// Instance
myInstance = new myClass();

// Outputs 0
console.log(myInstance.getAttribute());

myInstance.setAttribute(42);

// Outputs 42
console.log(myInstance.getAttribute());

Because of javascripts closure ability, the variable myAttribute in the code snippet should be private. This means that a direct access to the variable with e.g. myInstance.myAttribute should not be possible. A self made access to the variable would offer the class methods this.setAttribute and this.getAttribute.

Content

The user interaction part should look like the content as seen below by starting "index.html" in a web browser.

ERROR: No image found!

  • Every cup in the picture should be clickable.
  • Only one cup should be the right one and left clicking it, would give positive points. The other cups would give negative points if left clicked.
  • The riddle offers an option for compensating negative points. The answer would be checked automatically by giving the correct input.
  • Positive points for correct cup would be 50 when left clicked.
  • Positive points for riddle would be 30 when answered correctly.
  • Negative points for incorrect cups would be -15 when left clicked.
  • Maximal rounds would be 5 when played to the end.
  • 🅱️ utton "RESTART" should refreshe the page.

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