Jump to content

smus

Members
  • Posts

    177
  • Joined

  • Last visited

Posts posted by smus

  1. 13 hours ago, Ingolme said:

    Multiplication and division have the same precedence, addition and subtraction have the same precedence. When two operators of the same precedence are found, the leftmost operation is done first.

    Exactly, right. The precedence goes pair(* and /) over pair(+ and -) and the Win Calc must be set to a kind of formula mode to use precedence order, otherwise it counts numbers from left to right as they are. Thanks!

  2. eval() works in this case, but I am not sure what the right priority is (operator precedence) in Javascript. Some websites has info that divistion(/) has the highest priority then goes multiplication, addition and subtraction. That is strange, because usually multiplication is the first.

    1-2+3*4/5 = 1.4 according to JS compliler (/ then * then - then +, no idea why it counts like that)

    1-2+3*4/5 = 1.6 according to Windows Calc (I guess, it counts without any priority)

    1-2+3*4/5 = -3.4 if we use the correct operator precedence (* / + -)

    What I was taught in high school is that the correct precedence must be: * / + - Never thought that there might be another order in programming languages.

  3. Elements of an array of a math formula look like this:

    a = [1,'+',2,'-',3,'*',4,'/',5];

    How do I perform all the arythmetic actions between those numbers. The array elements may be different, because they are added dynamically.

    It would not be difficult if I didn't have to prioritize the actions (/,*,_,-). I tried using splice() method, but something goes wrong. Maybe I can somehow sort the elements according to the math actions priority?

  4.  

    I would like to create an array with 2 elements, for example. When I assign the length explicitly, it works well, but this code does not work:

    dim n=2

    dim a(n)

    a(0) = "first"

    a(1) = "second"

    response.write a(0)&a(1)

    how to set array length dynamically?

  5. On 6/4/2018 at 7:27 AM, PLight said:

    I have a need for creating checkbox names that go through a loop and are named by concatenating the name of the field with a number that is the loop index.

            <%if pDiscussed(i) <> "True" then%>
                <input type="checkbox" name="ynDiscussed" & CStr(i)  value="0" />
            <%else%>
                <input type="checkbox" name="ynDiscussed" & CStr(i)  value="1" checked />
            <%end if%></td>


    I've done this before with text boxes and there are no problems but somehow with a checkbox it will not work.  I've even tried using an array (ynDiscussed[]) along with...

            <%if pDiscussed(i) <> "True" then%>
                <input type="checkbox" name="ynDiscussed(" & CStr(i) & ")"  value="0" />
            <%else%>
                <input type="checkbox" name="ynDiscussed(" & CStr(i) & ")"  value="1" checked />
            <%end if%></td>

    but it doesn't like that either.

    I can't even substitute in a number instead of the CStr(i) and have it pick it up - my code reading: <input type="checkbox" name="ynDiscussed" & "1"  value="0" />

    Is this simply impossible or what am I missing?

    Any help is very much appreciated.  Cheers!

    if pDiscussed is of boolean type, you don't need quotes around the true value. 

    Try checked = "checked" as well

    What is stored in i variable? Is that (pDiscussed(i)) an array element?

  6. :) naive solution, because, hypothetically, headings might be scattered around the document.

    No, I was just wondering why developers invented such convenient thing, but did not apply it to tag names. Philosophical question :)

  7. Is it possible to apply to several tags with one selector, not creating class for it? For example, I want a common property for all headings in the document:

    h1, h2, h3{color: orange;}

    <h1>h1</h1>

    <h2>h2</h2>

    <h3>h3</h3>

    Something like h^{color: orange;} for tag selectors?

     

  8. What if I should count all the words in a text, that is not in a single tag. For example, there are a few <p> tags:

    <p>first paragraph</p><p>second paragraph</p><p>third paragraph</p>

    function countwords(){
    		var p = document.getElementsByTagName("p"), n = document.getElementById("n"), a=[],text = "", count = 0;
    		for(var x=0;x<p.length;x++){
    		  text = p[x].innerHTML;
    		  text = text.trim();
    		  a = text.split(" ");
    		  al = a.length;
    		  count = count + al;	
    		}
    		n.innerHTML = count;
    	}

    It works fine if I put a relatively small text. When I put there a pretty long text (around 300 words), the result is not correct.

    Does it count double or triple spaces between the words? But MS Word gives even higher result (374 instead of around 360 words).

  9. dsonesuk, I used IE, UCBrowser, TouchBrowser on my WP.

    I decided to cancel all the changes I've made in the code and to check it on an Android device. Everything works perfectly! Seems they didn't update browsers for WP for a long period of time.

    Thanks, dsonesuk and Ingolme

  10. Thanks, dsonesuk, I tried to transform the code as you've suggested. It doesn't work on my mobile device. If it is working on Android, it must be because the browser on the phone does not fully support HTML5. This code:

     <audio controls>
      <source src="../audio/smex.wav">
      Your browser does not support the audio tag.
    </audio>

    is working on Desktop, but gives the 'Invalid source' on the phone.

  11. 59 minutes ago, dsonesuk said:

    You seem to be using backticks instead of single quotes and what is ${a} ?

    try instead

    
    const audio = document.querySelector("audio[data-key='"+a+"']");

     

    Changed - absolutely the same.

    This code also works on the web, but does not on a mobile device:

    <audio class="newAudio" src="../audio/femalelaughter.mp3"></audio>
    
    <strong onclick="playSound()">alink</strong>
    
    <script>
         function playSound(){
           const audio = document.querySelector(".newAudio");   
           audio.currentTime = 0;
           audio.play();     
         }
    </script>

    What else? I also tried different browsers on my phone. I have Windows Phone, can anyone try it on iPhone or Android?

     

  12. Commented this string: document.getElementById(a).classList.add('playing'); Erased the ids from all the <audio> tags. It is the same: there is no sound. I even tried to include audio tag independently and check whether it is working on my mobile device, and it was working. I think I need to check my function in a different way.

    Might there be the absence of EcmaScript support by the mobile device browser?

    I suspect that it may not work because of how it takes the data-key parameter from the audio tag:

    const audio = document.querySelector(`audio[data-key="${a}"]`);

  13. 30 minutes ago, justsomeguy said:

    Not according to what you posted above.  I see 2 elements with the ID "76".  

    Exactly, you are right. I am using duplicate IDs here only for getting them from inside of the tag, the function uses data-keys.

    33 minutes ago, justsomeguy said:

    OK, I'm confused.  Does alert work, or does it not work, when it is in your onclick handler?  When the only line of code inside your onclick handler is a call to alert, do you see it?  You need to actually comment out or remove the other lines of code to test that, just adding an alert line is not the right test. 

    Here is how I am checking:

    <strong id="76" onclick="alert(this.id)">L is for Laugh</strong><br>

    It works on both PC and mobile

  14. 7 minutes ago, justsomeguy said:

    So, what's happening?  If you put an alert inside that function, you don't see the alert on mobile browsers?  If you do see the alert, I would suspect using a template string for querySelector.  I would also point out that you have multiple elements with the same ID.

    No IDs are different. I've just tried putting an 'alert' directly onclick, and it worked. The function doesn't work at all, no matter what's inside. 

  15. 20 hours ago, justsomeguy said:

    Mobile devices have their own set of events.  There are actual touch events.  Some mobile browsers might, and probably do, implement onclick also, but there are a series of events just for touch screens.

    https://developer.mozilla.org/en-US/docs/Web/API/Touch_events

    Do you mean alert instead of alarm?  If your basic test using alert works, and something else doesn't work, then the problem is not the event, but whatever you're doing in the handler.

    Oh, yes, right, it is 'alert'. There are some <audio> tags involved, and my function makes one of them start playing, depending on data-key id:

    <strong id="76" onclick="makeLaughM(this.id)">L is for Laugh</strong><br>
    
    <audio id="76" data-key="76" src="audio/smex.wav"></audio>
    <audio id="65" data-key="65" src="audio/laugh.mp3"></audio>
    <audio id="85" data-key="85" src="audio/laugh2.mp3"></audio>
    <audio id="71" data-key="71" src="audio/snortlaugh.mp3"></audio>
    <audio id="72" data-key="72" src="audio/femalelaughter.mp3"></audio>
    
    <script>
    function makeLaughM(a){
           const audio = document.querySelector(`audio[data-key="${a}"]`);
           audio.currentTime = 0;
           audio.play();
           document.getElementById(a).classList.add('playing');
           document.getElementById('facecolor').style.fill = "orange";   
         }
    </script>

     

  16. So onclick event on a desk-, laptop computers does the same as when we tap on an element on our mobile devices, right? I always thought these two actions are totally similar.

    Why then the function might not be working 'on tap', however everything works fine on PC?

    I checked the browser version on a mobile device, it supports HTML5 tags. I also tried to create a simple function showing message using 'alarm' and it also works. 

    What might be a possible reason?

×
×
  • Create New...