[Solved] Showing Correct and Incorrect in a quiz [closed]

Try this 😉 var score = 0; var questions = [ [‘Question One?’, ‘1 Answer’], [‘Question Two?’, ‘2 Answer’], [‘Question Three?’, ‘3 Answer’], [‘Question Four?’, ‘4 Answer’], [‘Question Five?’, ‘5 Answer’], [‘Question Six?’, ‘6 Answer’] ]; var cA = []; var incorrect = []; function askQuestion(question, index) { var answer = prompt(question[0], ”); if (answer … Read more

[Solved] Replace the numbers with *

To replace the last 2 digits with some characters, firstly convert it to a string and then, using the slice() method, append the characters. You can read more about the slice() method in its MDN Documentation. let numberAsString = Math.random().toString(); //your number as a string let result = numberAsString.slice(0, -2) + ‘**’; //cut and append … Read more

[Solved] How to sum of table amount in javascript? [closed]

Like this: var tr = “”; var totalAmount = “”; var total = 0; //this your total var footerTr = “”; for(var i=1; i<=31; i++){ tr += `<tr> <td>${i}</td> <td>${i*2}</td> </tr>`; totalAmount += `${i*2}+`; total += i*2; //this your total } totalAmount = totalAmount.substring(0, totalAmount.length – 1); // remove last plus totalAmount += ‘=’+total; footerTr … Read more

[Solved] Angular and $q: strangely, nothing is working at all

Loads of bugs in the old code. Here’s a fixed plnkr: http://plnkr.co/edit/NN0eXFg87Ys2E3jjYQSu?p=preview The problem mostly was that you didn’t assign your receive function properly to the scope. It must be done like so: $scope.receive = function() { Your code was like $scope.receive(function() { solved Angular and $q: strangely, nothing is working at all

[Solved] How can I sum object values by array data using ES standard? [closed]

A reduce and forEach to group by tag and then taking the values for each tag var a= [ { “cost”: 500, “revenue”: 800, “tag”: [ “new”, “equipment”, “wholesale” ] }, { “cost”: 300, “revenue”: 600, “tag”: [ “old”, “equipment” ] }, { “cost”: 800, “revenue”: 850, “tag”: [ “wholesale” ] } ] let x … Read more

[Solved] How can I show only table rows that contains a radio button value? [closed]

You can use jQuery filter function to detect the value. $(document).ready(function(){ $(‘input[name=”filter”]’).change(function(){ var value = $(this).val().toLowerCase(); if (value === “all”){ $(“#myTable tr”).show(); } else { $(“#myTable tr”).filter(function() { $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1) }); } }); }); .table{ width: 100%; border: 1px solid #ddd; } .table tr, .table th, .table td{ border: 1px solid #ddd; } <script … Read more

[Solved] How to group the second elements of multiple nested arrays based on first element in javascript? [closed]

You can reduce your array to produce the desired result like this let firstArray = [[0,2], [1,3], [0,5], [2,8], [1,4], [4,2]]; const secondArray = firstArray.reduce((acc, [ idx, val ]) => { acc[idx] = acc[idx] ?? [] // initialise to an empty array acc[idx].push(val) // add the value return acc }, []).filter(Boolean) // filter skipped indices … Read more

[Solved] DOM manipulation with JavaScript or jQuery by moving element inside of its sibling [closed]

Got it! I forgot to put .length after $titleArray and I used appendTo() instead of prependTo(). Although the code doesn’t look so elegant now. But it’s a good start. var $titleArray = $(‘.title’); for (var i = 0 ; i < $titleArray.length; i++){ var $imageWrapper = $($titleArray[i]).parent().prev(); $($titleArray[i]).prependTo($imageWrapper); }; solved DOM manipulation with JavaScript or … Read more

[Solved] Does onclick work with any positioning? [closed]

Absolute positioning has no effect on how the onClick event is being fired. You are simply positioning your element below another element, so another element is blocking the mouse event Try adding to your CSS: #cogdiv { z-index: 9999; //or greater, or 1. Just make sure it’s bigger than the overlapping element’s z-index } Reading … Read more

[Solved] RegExp name validation using hexadecimal metacharacters

The range you are using is Greek extended. You want the range from 0370 to 03ff. From the page you quoted: 0370..03FF; Greek and Coptic 1F00..1FFF; Greek Extended function is_greek(name){ var greek = /[\u0370-\u03ff]/; return greek.test(name); } > is_greek(“α”) < true 1 solved RegExp name validation using hexadecimal metacharacters

[Solved] How do I delay an execution in Javascript?

You could use setTimeout(function(){dosomething}, timeout), btw. add console.log(‘something’) to see if the functions are actually executed. btw. if you’re using interval remember you might need to cancel it if you dont want it running forver, you could as well use recurring function (a function calling itself) with some condition on when to do processing or … Read more

[Solved] Setting min and max font size for a fixed-width text div that accepts variable text [closed]

Add an event listener to some changing property and then change the font size accordingly. document.getElementById(“testInput”).addEventListener(“keyup”, function(){ var inputText = document.getElementById(“testInput”).value; document.getElementById(“test”).innerHTML = inputText; if(inputText.length > 10){ document.getElementById(“test”).style.fontSize = “8px”; }else if(inputText.length > 5){ document.getElementById(“test”).style.fontSize = “10px”; }else{ document.getElementById(“test”).style.fontSize = “12px”; } }); <input id=”testInput”> <div id=”test”></div> 1 solved Setting min and max font size … Read more