Jump to content

Ingolme

Moderator
  • Posts

    14,894
  • Joined

  • Last visited

  • Days Won

    176

Posts posted by Ingolme

  1. Those characters would be something like left arrows and right arrows. Your document's character set has not been specified. You need to do two things:

    1. In your code editor, make sure that the character encoding is set to UTF-8 before saving the HTML file.
    2. Add a <meta> tag in the <head> indicating which character encoding is being used in the document like the following:
    <meta charset="UTF-8">

     

    • Thanks 1
  2. The reason you're finding code that prints all of the terms up to N is because that is what a progression is: a sequence of terms.

    Math.pow() already provides everything you need to find any one term in a geometric progression, which is why browsers will never implement a more specific function to do it. If browsers had a dedicated built-in function for every single little problem somebody wanted to solve there would be millions of them.

    The formula for a term is right on the page you linked to:

    TN = a1 * r(n-1)

    The code is simple:

    function geometricProgression(a1, r, n) {
      return a1 * Math.pow(r, n-1);
    }

    Putting into the HTML with the inputs and outputs it would look like this:

    Progression factor: <input type="number" id="factor" value="2"><br>
    Term number: <input type="number" id="term" value="1">
    <button onclick="myExample()">Convert</button>
    
    <p id="exmpone1"></p>
    
    <script>
    function myExample() {
      var factor = Number(document.getElementById("factor").value);
      var term = Number(document.getElementById("term").value);
      document.getElementById("exmpone1").innerHTML = geometricProgression(factor, factor, term);
    }
    
    function geometricProgression(a1, r, n) {
      return a1 * Math.pow(r, n-1);
    }
    </script>

     

  3. You can use the attribute ^= selector on the class attribute. It would look something like this: [class^="col-"].

    Though this will only match elements where the first class in the attribute begins with "col", it would not match <div class="something col-sm-4"> because the attribute starts with "something".

  4. There is no way for the server to predict what a computer's next IP address will be, so I can't think of any way it could work.

    If you happen to have a list of all the IP addresses that may be assigned to the computer you could allow all of them.

  5. Those are bitwise assignment operators. They perform a bitwise operation and then assign the result to a variable.

    It looks like the W3Schools Java tutorial does not have any information about how bitwise operators work, probably because it is difficult to explain in simple terms.

    Bitwise operators treat whole numbers as sequences of 1s and 0s. Each 1 or 0 is called a bit. There are several operations you can do with bits, which are mostly similar to the logical operators. There is & (and), | (or), ~ (not), ^ (exclusive or), << (shift left) and >> (shift right).

    The sequences of 1s and 0s are called binary representations of the numbers. For example, 5 in binary is 101 and 3 in binary is 011.

    & operator

    • Decimal: 5 & 3 = 1
    • Binary: 101 & 011 = 001

    | operator

    • Decimal: 5 | 3 = 7
    • Binary: 101 | 011 = 111

    ~ operator (Since integers have 32 or 64 bits, and all the zeroes need to be taken into account, and computers treat large binary numbers beginning with 1 as negative, this one is actually more complicated to describe)

    • Decimal: ~5 = -6
    • Binary: ~00000000000000000000000000000101 = 11111111111111111111111111111010

    ^ operator

    • Decimal: 5 ^ 3 = 6
    • Binary: 101 ^ 011 = 110

    << operator Moves bits a certain number of positions to the left (This is equivalent to dividing by 2 a number of times and removing any decimal part from the result)

    • Decimal: 5 << 2 = 20
    • Binary: 101 << 2 = 10100

    >> operator Moves bits a certain number of positions to the right (This is equivalent to multiplying a number by 2 a number of times)

    • Decimal: 5 >> 2 = 1
    • Binary: 101 >> 2 = 001
  6. PHP and Javascript operate in two completely different environments. PHP generates Javascript code and Javascript is unaware that PHP was running at all.

    You could even write something this and it could potentially generate usable Javascript:

    var <?php echo $_SESSION['varname'] ?> = "Hello World!";

     

    In order to have Javascript treat something as a string, it has to be wrapped in quotation marks. On PHP's end, you'll want to escape any quotation marks that are in the string itself. A working example should look something like this:

    var s = "<?php echo addslashes($_SESSION['subscriptionid']); ?>";

     

  7. Javascript has a feature where you can access any object's properties or methods using square brackets and a string inside.

    window.alert() is the same as window["alert"]().

    myClass.value is the same as myClass["value"].

    Since the square bracket notation uses a string instead of an identifier, you can put a variable containing a string within the square brackets.

    • Like 1
  8. I think it should work if you use strings instead. Selecting methods dynamically is going to be pretty confusing to anybody who has to maintain your code. I think it's a practice which should be avoided.

    ...
    ...
    
        constructor(){
        	this.config = { "branch": "branchA" };
            this.classVar = {"a":1}
        }
        main(){
        	this.classVar["b"] = 2;
            this.branchB();
            this[this.config.branch]();
        }
    
    
    ...
    ...
    
    var myClass = new MyClass();
    myClass.main();
    myClass.config.branch = "branchB";
    myClass.main();

     

    • Like 1
  9. I have removed the code from your previous post.

    When posting code, don't post more than around 20 lines because anything more and nobody is going to want to read all of it. You must only post the few lines of code that are related to the particular problem you are trying to solve.

×
×
  • Create New...