[Solved] Write a function firstWord, taking a string and returning the first word in that string. The first word are all characters up to the first space [closed]

There are several problems with your code: go and run is not a valid parameter declaration in the function header. There is confusion here with the parameter and the string value that you expect the function to be called with. In the function header you should list the parameter(s) with variable names. Since the function … Read more

[Solved] How Do You Run the ENTIRE Javascript Page From An Button In HTML?

I’ve created an entry on JSBin suggesting many improvements to what you have now: http://jsbin.com/epurul/3/edit Visit the entry to test the code yourself. Here is the content, for convenience: HTML: <body> <button onclick=”playGame()”>Play Game</button> </body> And JavaScript: // Expose playGame as a top-level function so that it can be accessed in the // onclick handler … Read more

[Solved] Radius through input [closed]

It sounds like what you want to do is geocode an address and plant a circle around it. Keep in mind that you have to bind a Google Map to a DOM element, which is this sample code is a div with an id of “map”. function geocodeAndMap(address) { var geocoder = new google.maps.Geocoder(); geocoder.geocode( … Read more

[Solved] how to make an asynchronous javascript function synchronous

for others that will be in the same situation as I am, here is the solution. first step, I made the captcha function to return a promise function captcha() { return new Promise(function(resolve, reject) { grecaptcha.ready(function() { grecaptcha.execute(recaptcha_site_key, {action: ‘run’}).then(function(token) { resolve(token); }); }); }); } second step, async/await for the variable to become available … Read more

[Solved] Why can’t I put JS code between CODE?

You can specify the src attribute or include the code as the content of the script tag. As you’ve discovered, you can not do both simultaneously. Here’s what Mozilla Developer Network has to say about the src attribute (emphasis at the end added): This attribute specifies the URI of an external script; this can be … Read more

[Solved] What is wrong with this function

There is something wrong with those characters. Retyping load and alert fixes the issue for me. So I’m guessing there might be some hidden ASCII characters somewhere in them. (Quentin explains the reason in his answer: https://stackoverflow.com/a/51170307/5894241) Here’s the updated snippet: function lоаd() { аlert(‘Hello!’); } window.onload = load; Here’s your current snippet for reference: … Read more

[Solved] Count the number of buttons present inside a div

Many ways: Javascript: document.querySelectorAll(‘#maindiv button’) JQuery: $(‘#maindiv button’) var buttons = document.querySelectorAll(‘#maindiv button’) console.log(buttons.length) <div id=’maindiv’> <button></button> <button></button> <button></button> <button></button> <button></button> </div> 2 solved Count the number of buttons present inside a div

[Solved] I need to work it like but using javascriptIs there any javascript function to forward to another page? [closed]

Java practices site sums it up nicely: Forward a forward is performed internally by the servlet the browser is completely unaware that it has taken place, so its original URL remains intact any browser reload of the resulting page will simple repeat the original request, with the original URL Redirect a redirect is a two … Read more

[Solved] Javascript User Input [closed]

Use radio buttons <form> <fieldset id=”group1″> <input type=”radio” value=”” name=”group1″> <input type=”radio” value=”” name=”group1″> </fieldset> <fieldset id=”group2″> <input type=”radio” value=”” name=”group2″> <input type=”radio” value=”” name=”group2″> <input type=”radio” value=”” name=”group2″> </fieldset> </form> This answer is from here Multiple radio button groups in one form If you edit the code a bit you get (You use value1 … Read more

[Solved] JavaScript for loop [closed]

The code does not run because of the following issues function multiple ( ). Though there is a closing } but there is no opening { which mark the start of function body. The function body should be inside { } . Example function multiple() { //Rest of code} for (i=pooya;i<=5;i++){}. This part will not … Read more

[Solved] Find closing tag in HTML string

some change in your code can work see this line of codes function highlightsText() { var range, sel; if (window.getSelection) { sel = window.getSelection(); if (sel.getRangeAt) { range = sel.getRangeAt(0); } document.designMode = “on”; if (range) { sel.removeAllRanges(); sel.addRange(range); } if ( !document.execCommand(“HiliteColor”, false, “yellow”) ) { document.execCommand(“BackColor”, false, “yellow”); } document.designMode = “off”; } … Read more

[Solved] How to combine values in the array? [closed]

You’d get the spans and map back the text content var text = [].map.call(document.querySelectorAll(‘.topics span’), function(elem) { return elem.textContent; // or elem.dataset.value for the data-attribute }); console.log(text) <div class=”topics”> <span class=”topic” data-value=”hello”>hello</span> <span class=”topic” data-value=”world”>world</span> <span class=”topic” data-value=”one”>one</span> <span class=”topic” data-value=”two”>two</span> <span class=”topic” data-value=”six”>six</span> </div> 2 solved How to combine values in the array? [closed]