Jump to content

smus

Members
  • Posts

    177
  • Joined

  • Last visited

Posts posted by smus

  1. I am not familiar with classes, so I need a solution, or, at least, a clue, please!                    

    This code causes the error: TypeError: Cannot read property 'vendor' of undefined

    When I am trying to check its correctness, the interpreter also informs that the context is not bound to the 'getInfo' method

    How can we correct classes in order to avoid the error? 

    class Transport {
      constructor(type, price, vendor, model) {
        this.type = type;
        this.price = price;
        this.vendor = vendor;
        this.model = model;
      }
    
      getInfo() {
        return `${this.vendor}, ${this.model}`;
      }
    
      getPrice() {
        return this.price + '$';
      }
    }
    
    class Car extends Transport {
      constructor(vendor, model, doorsCount, price) {
        super('car', price, vendor, model);
        this.doorsCount = doorsCount;
      }
    
      getDoorsCount() {
        return `Number of doors: ${this.doorsCount}`;
      }
    }
    
    class Bike extends Transport {
      constructor(vendor, model, maxSpeed, price) {
        super('bike', price, vendor, model);
        this.maxSpeed = maxSpeed;
      }
    
      getMaxSpeed() {
        return `Max speed: ${this.maxSpeed} kmh`;
      }
    }

     

  2. <ul class="cards">
          <li class="two heart"></li>
          <li class="five diamond"></li>
          <li class="ten heart"></li>
          <li class="jack club"></li>
          <li class="queen spade"></li>
          <li class="king diamond"></li>
          <li class="ace heart"></li>
          <li class="six heart"></li>
          <li class="seven diamond"></li>
          <li class="eight spade"></li>
          <li class="nine club"></li>
          <li class="three club"></li>
          <li class="four heart"></li>
        </ul>
        <ul class="cards">
          <li class="five spade"></li>
          <li class="six diamond"></li>
          <li class="seven spade"></li>
          <li class="eight club"></li>
          <li class="two diamond"></li>
          <li class="three heart"></li>
          <li class="four club"></li>
          <li class="queen club"></li>
          <li class="king spade"></li>
          <li class="seven diamond"></li>
          <li class="nine heart"></li>
          <li class="ten diamond"></li>
          <li class="jack heart"></li>
        </ul>
        <ul class="cards">
          <li class="two spade"></li>
          <li class="ten heart"></li>
          <li class="ace club"></li>
          <li class="five heart"></li>
          <li class="nine diamond"></li>
          <li class="king diamond"></li>
          <li class="ace spade"></li>
          <li class="six heart"></li>
          <li class="eight diamond"></li>
          <li class="ace spade"></li>
          <li class="queen heart"></li>
          <li class="three diamond"></li>
          <li class="four spade"></li>
        </ul>
        <ul class="cards">
          <li class="king heart"></li>
          <li class="jack club"></li>
          <li class="two club"></li>
          <li class="three spade"></li>
          <li class="four diamond"></li>
          <li class="ten club"></li>
          <li class="jack spade"></li>
          <li class="eight diamond"></li>
          <li class="nine spade"></li>
          <li class="queen diamond"></li>
          <li class="five club"></li>
          <li class="six club"></li>
          <li class="seven heart"></li>
        </ul>

    How can we call to all even <li> inside the first <ul>?

    I tried something like:

    li:nth-child(even) ul.cards:first-child{
      background-color: #996666;
    }

     

  3. Since there is no 'NodeJS/MongoDB' discussion section I decided to post my question to 'JavaScript'.

    I am trying to start the server by running mongod.exe, and by doing the same thing using cmd. I want to start the server and use it with a tool called Robo 3T to manipulate NoSQL databases. There is no active connection can be seen in Robo 3T after I start mongo. 

    Can anyone explain what I am supposed to do? What is the correct way to run MongoDB on Windows?

  4. Yes, you can, by using pure CSS (not necessarilly with W3.css). Try something like this:

    <style>
    .label:after{
        content:'text I want to change';
    }
    .label:hover:after{
        content:'changed text';
    }
    </style>
    <body>
    <p>text <span class="label"></span> text</p>
    </body>

     

  5. The page already goes with <style>section{display:none}</style> written in it. Adding and removing classes won't influence it.

    I also tried section.style.display='unset' which provides the same result as 'initial', and section.style.display=' ', but it does not work at all.

    As it is discussed here: https://stackoverflow.com/questions/18534561/what-is-use-of-initial-value-in-css 'initial' only resets to a CSS default, not to a browser default. And they only plan to add something in CSS4. While we are waiting the only reasonable way I thought about is to check each element if it is actual initial style property is 'block' or not, before switching it back from 'display:none'. Something like:  if(element.tagName == 'div'){element.style.display = 'block'}... ☺️

     

     

  6. 1 hour ago, dsonesuk said:

    Give it a id ref use that id ref in document.getElementById() and style it how you want. It will add style="display: inline;" (if you styled it as inline) being inline to the element it will have a higher precedence over styling created in css stylesheet UNLESS you used !important with it. using document.getElementById("elementsid").style.display="initial";  should also revert to elements default display value.


    Very helpful, thanks! display = "initial" works, however, it changes the style not to display = "block" (which is default one for <section> tag), but to display = "inline". I wonder what the result would be if we do the following:

    <style>
    
    section{display:none} 
    
    </style>
    
    <script>
    
    document.getElementsByTagName('section')[0].style.display = 'block'
    
    document.getElementsByTagName('section')[0].style.display = 'initial'
    
    </script>

    will it switch back to display = 'inline'? If so, why? 

  7. For example, an element's default value is 'inline'. It was as 'display:block' on my page, but now it is hidden by 'display:none'. I want it back to visible again, but to its default state.

    I tried element.style.display = "", element.style.display = "auto", as well as element.style.removeProperty = "display", as it is described here: https://stackoverflow.com/questions/21457904/change-element-display-none-back-to-default-style-value-js

    But it could not be changed from 'display:none' (only by using 'display:block')

    There is an official list of default style properties, like, for example, this one: https://www.w3schools.com/cssref/css_default_values.asp

    but is there a way to get it by JavaScript?

  8. 15 hours ago, justsomeguy said:

    I wouldn't count on the filesystem returning data the way you want, I would get the list of all of the files and folders, sort them however you want to sort them, and print the sorted list.

    You mean I place them in an array, sort the elements as I want and display them in that order? That makes sense. Because now it only iterates through the folders and prints it out as it was returned from the file system.

  9. <%@LANGUAGE="VBSCRIPT"%>
    <%
       Option Explicit
       On Error Resume Next
    
       ' this section is optional - it just denies anonymous access
       ' If Request.ServerVariables("LOGON_USER")="" Then
       '   Response.Status = "401 Access Denied"
       'End If
    
       ' declare variables
       Dim objFSO, objFolder
       Dim objCollection, objItem
    
       Dim strPhysicalPath, strTitle, strServerName
       Dim strPath, strTemp
       Dim strName, strFile, strExt, strAttr
       Dim intSizeB, intSizeK, intAttr, dtmDate
    
       ' declare constants
       Const vbReadOnly = 1
       Const vbHidden = 2
       Const vbSystem = 4
       Const vbVolume = 8
       Const vbDirectory = 16
       Const vbArchive = 32
       Const vbAlias = 64
       Const vbCompressed = 128
    
       ' don't cache the page
       Response.AddHeader "Pragma", "No-Cache"
       Response.CacheControl = "Private"
    
       ' get the current folder URL path
       strTemp = Mid(Request.ServerVariables("URL"),2)
       strPath = ""
    
       Do While Instr(strTemp,"/")
          strPath = strPath & Left(strTemp,Instr(strTemp,"/"))
          strTemp = Mid(strTemp,Instr(strTemp,"/")+1)      
       Loop
    
       strPath = "/" & strPath
    
       ' build the page title
       ' strServerName = UCase(Request.ServerVariables("SERVER_NAME"))
       strTitle = "sitelist"
    
       ' create the file system objects
       strPhysicalPath = Server.MapPath(strPath)
       Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
       Set objFolder = objFSO.GetFolder(strPhysicalPath)
    %>
    <html>
    <head>
    <title>The list of websites available</title>
    <base target="blank">
    <style>
    BODY  {background: hsl(24, 100%, 70%);  }
    a {text-decoration:none;}
    a:hover {color:darkred;font-weight:600;}
    a:active {text-decoration:none;}
    </style>
    </head>
    <body class="w3-container">
    <br>
    <h2 align="center"><%=strTitle%></h2>
    <div align="center"><center>
    
    <table border="0" cellspacing="0" cellpadding="2" style="BACKGROUND: #000000; width:70%">
    <!--
    <tr>
       <th align="left">Name</th>
       <th align="left">Bytes</th>
       <th align="left">KB</th>
       <th align="left">Attributes</th>
       <th align="left">Ext</th>
       <th align="left">Type</th>
       <th align="left">Date</th>
       <th align="left">Time</th>
    </tr>
    -->
    <%
       ''''''''''''''''''''''''''''''''''''''''
       ' output the folder list
       ''''''''''''''''''''''''''''''''''''''''
    
       Set objCollection = objFolder.SubFolders
    
       For Each objItem in objCollection
          strName = objItem.Name
          strAttr = MakeAttr(objItem.Attributes)      
          dtmDate = CDate(objItem.DateLastModified)
    %>
    <tr>
       <td align="center" style="background: hsl(60, 100%, 75%);COLOR: #000000;font-family:courier;font-size:20px;"><a class="link hvr-underline-from-center" href="<%=strName%>"><%=strName%></a></td>
    <!--
       <td align="right">N/A</td>
       <td align="right">N/A</td>
       <td align="left"><tt><%=strAttr%></tt></td>
       <td align="left"><b><DIR></b></td>
       <td align="left"><b>Directory</b></td>
       <td align="left"><%=FormatDateTime(dtmDate,vbShortDate)%></td>
       <td align="left"><%=FormatDateTime(dtmDate,vbLongTime)%></td>
    -->
    </tr>
    <% Next %>
    <!-- 
    <%
       ''''''''''''''''''''''''''''''''''''''''
       ' output the file list
       ''''''''''''''''''''''''''''''''''''''''
    
       Set objCollection = objFolder.Files
    
       For Each objItem in objCollection
          strName = objItem.Name
          strFile = Server.HTMLEncode(Lcase(strName))
    
          intSizeB = objItem.Size
          intSizeK = Int((intSizeB/1024) + .5)
          If intSizeK = 0 Then intSizeK = 1
    
          strAttr = MakeAttr(objItem.Attributes)
          strName = Ucase(objItem.ShortName)
          If Instr(strName,".") Then strExt = Right(strName,Len(strName)-Instr(strName,".")) Else strExt = ""
          dtmDate = CDate(objItem.DateLastModified)
    %>
    <tr>
       <td align="left"><a href="<%=strFile%>"><%=strFile%></a></td>
       <td align="right"><%=FormatNumber(intSizeB,0)%></td>
       <td align="right"><%=intSizeK%>K</td>
       <td align="left"><tt><%=strAttr%></tt></td>
       <td align="left"><%=strExt%></td>
       <td align="left"><%=objItem.Type%></td>
       <td align="left"><%=FormatDateTime(dtmDate,vbShortDate)%></td>
       <td align="left"><%=FormatDateTime(dtmDate,vbLongTime)%></td>
    </tr>
    <% Next %>
    -->
    </table>
    </center></div>
    <br><br>
    </body>
    </html>
    <%
       Set objFSO = Nothing
       Set objFolder = Nothing
    
       ' this adds the IIf() function to VBScript
       Function IIf(i,j,k)
          If i Then IIf = j Else IIf = k
       End Function
    
       ' this function creates a string from the file atttributes
       Function MakeAttr(intAttr)
          MakeAttr = MakeAttr & IIf(intAttr And vbArchive,"A","-")
          MakeAttr = MakeAttr & IIf(intAttr And vbSystem,"S","-")
          MakeAttr = MakeAttr & IIf(intAttr And vbHidden,"H","-")
          MakeAttr = MakeAttr & IIf(intAttr And vbReadOnly,"R","-")
       End Function
    %>

    I am using the code above (in a separate index.asp file) to list all the subfolders in a current folder.

    It works under IIS and displays the names of all the subfolders (as a hyperlinks to browse to a subfolder). It always sorted them alphabetically (a - z), but now (after folders restoration) it started to add new folders to the bottom of the list, regardless of their name. I've already tried many things: restarted IIS, changed folders attributes etc., but it is the same, however, it works properly on the external webhosting service. What can be wrong? IIS settings? I've changed the file system when I was restoring those folders and files, from NTFS to exFAT, might that be the probable reason?

  10. Solved it! I was unattentive to include the additional <span> tag inside <td></td> (for the styles).

    It sorts normally without it, or with it if we use innerText instead of innerHTML

  11. <!-- the table header -->
    
    <table class='indextable' align='center'><th  onclick='sortTable(this.parentNode.parentNode,0)'>Subject</th><th onclick='sortTable(this.parentNode.parentNode,1)'>Questions</th><th>Edit</th>
    
    <!-- the javascript function -->
    
    <script>
    
    function sortTable(t,n) {
      var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0, intx, inty;
      table = t;//document.getElementsByClassName("indextable")[0];
      switching = true;
      // Set the sorting direction to ascending:
      dir = "asc";
      /* Make a loop that will continue until
      no switching has been done: */
      while (switching) {
        // Start by saying: no switching is done:
        switching = false;
        rows = table.rows;
        /* Loop through all table rows (except the
        first, which contains table headers): */
        for (i = 1; i < (rows.length - 1); i++) {
          // Start by saying there should be no switching:
          shouldSwitch = false;
          /* Get the two elements you want to compare,
          one from current row and one from the next: */
          x = rows.getElementsByTagName("TD")[n];
          y = rows[i + 1].getElementsByTagName("TD")[n];
          /* Check if the two rows should switch place,
          based on the direction, asc or desc: */
    
     
          if (dir == "asc") {
            if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
              // If so, mark as a switch and break the loop:
              shouldSwitch = true;
              break;
            }
          } else if (dir == "desc") {
            if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
              // If so, mark as a switch and break the loop:
              shouldSwitch = true;
              break;
            }
          }
        }
    
    </script> 

     

  12. What I am doing is that I am only adding the condition. If it is the second row of the table (n==1), convert the x.innerHTML to an integer value using parseInt or Number.

    It does not react onclick, but the first row keeps on sorting the values out.

  13. Here's the code:

    <!-- the table header -->

    <table class='indextable' align='center'><th  onclick='sortTable(this.parentNode.parentNode,0)'>Subject</th><th onclick='sortTable(this.parentNode.parentNode,1)'>Questions</th><th>Edit</th>

    <!-- the javascript function -->

    <script>

    function sortTable(t,n) {
      var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0, intx, inty;
      table = t;//document.getElementsByClassName("indextable")[0];
      switching = true;
      // Set the sorting direction to ascending:
      dir = "asc";
      /* Make a loop that will continue until
      no switching has been done: */
      while (switching) {
        // Start by saying: no switching is done:
        switching = false;
        rows = table.rows;
        /* Loop through all table rows (except the
        first, which contains table headers): */
        for (i = 1; i < (rows.length - 1); i++) {
          // Start by saying there should be no switching:
          shouldSwitch = false;
          /* Get the two elements you want to compare,
          one from current row and one from the next: */
          x = rows.getElementsByTagName("TD")[n];
          y = rows[i + 1].getElementsByTagName("TD")[n];
          /* Check if the two rows should switch place,
          based on the direction, asc or desc: */

     
          if (dir == "asc") {
            if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
              // If so, mark as a switch and break the loop:
              shouldSwitch = true;
              break;
            }
          } else if (dir == "desc") {
            if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
              // If so, mark as a switch and break the loop:
              shouldSwitch = true;
              break;
            }
          }
        }

    </script>

     

×
×
  • Create New...