Counter JavaScript

Progetti JavaScript

In questo articolo, esploreremo la creazione di un counter in JavaScript, fornendo implementazioni che consentono sia l’incremento che il decremento in modi diversificati e interessanti. Realizziamo un counter in JavaScript In questo primo progetto, ci immergeremo nella creazione di un counter utilizzando esclusivamente JavaScript Vanilla. Sperimentate cliccando sui pulsanti sottostanti per incrementare o decrementare la … Leggi tutto

JavaScript to do list

To do list in JavaScript

In this lesson we will create a simple JavaScript to do list, a classic JavaScript exercise that allows you to experiment with the methods learned so far. To carry out this project, in fact, we will use some methods to manipulate the DOM in JavaScript. In the meantime, try the project that we are going … Leggi tutto

to do list in JavaScript

To do list in JavaScript

In questa lezione realizzeremo una semplice to do list in JavaScript. Si tratta di un esercizio classico che ci permetterà di mettere in pratica i concetti appresi finora e di sperimentare l’utilizzo di JavaScript per manipolare il DOM e gestire eventi. Per realizzare questo progetto infatti utilizzeremo alcuni metodi per manipolare il DOM in JavaScript. … Leggi tutto

JavaScript eval

eval JavaScript

The eval function in JavaScript evaluates the expression passed as an argument and executes it if there is an operation. The syntax is as follows: eval(string). JavaScript eval examples Here is a series of demonstrative examples on the use of eval. console.log(eval(‘2 + 13’)); var x = 10; var y = 3; console.log(eval(‘x + y’)); … Leggi tutto

JavaScript string

String JavaScript

In this lesson we will study the JavaScript String function that is used to return a string from a value passed as an argument. The syntax is as follows: string(object). Where object can be a number value, a Boolean value. JavaScript string examples These are some examples: console.log(String(’13years’)); console.log(String(‘thirteen’)); console.log(String(’13:50′)); console.log(String(’13-01-20′)); console.log(String(’13 01 20′)); console.log(String(‘true’)); … Leggi tutto

JavaScript parseFloat

parsefloat

In JavaScript the parseFloat function takes a string as an argument and returns a decimal number. The syntax is therefore the following: parseFloat(string). Where string represents the string to convert. This function, as well as the previous parseInt determines if the first character of the string is a number and continues until it finds a … Leggi tutto

JavaScript multiplication table

JavaScript multiplication table

In this lesson we build in JavaScript a simple multiplication table. To make this example, we will therefore create an html table and in each cell we will insert our elements. Let’s go back to the example above to understand how to get the elements to be inserted in the cells: From the figure we … Leggi tutto

prime number JavaScript

Numeri primi in JavaScript

In this lesson we develop a prime number algorithm in JavaScript. First of all, remember that a number is prime when it has two divisors, namely 1 and itself. The sequence of prime numbers begins with 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, … prime number JavaScript – algorithm Check if … Leggi tutto

JavaScript join

join JavaScript

In this lesson we introduce the JavaScript join method which, given an array, returns a string. This method is similar to the previous toString, discussed in the previous lesson. The difference with the toString method is that the latter can also be used on other variables, while join is used only with arrays. Also in … Leggi tutto

JavaScript slice

slice JavaScript

In this lesson we will talk about the JavaScript slice method useful for selecting elements of an array. This method returns a new array with the selected elements. The syntax of slice() is as follows: array.slice(start, end). The start and end parameters are optional. The beginning is a numerical value that indicates where the selection … Leggi tutto

JavaScript forEach

JavaScript forEach

JavaScript forEach method is used over arrays to iterate and apply a function to each element. This method was introduced starting with ECMAScript 5 (ES5), along with other features. The syntax is as follows: array.forEach(function(currentValue, index, array), thisValue). Where the function is required, therefore mandatory, while thisValue is optional and represents the value to pass … Leggi tutto

JavaScript splice

splice JavaScript

The JavaScript splice method adds and removes elements to an array starting from a specified location. The syntax is as follows: array.splice(index, q, element1,…, elementN). Where index represents the index from which to start and can be a negative value, which indicates that it starts from the end of the array. The quantity q represents … Leggi tutto

JavaScript reverse

reverse JavaScript

In this lesson we study JavaScript reverse method, which is useful for reversing the elements of an array. The syntax is as follows: array.reverse(). So let’s take some examples to understand how it works. JavaScript reverse – first example Reverse the order of an array of strings taken as input, using the reverse() method. So … Leggi tutto

JavaScript sort

sort JavaScript

In this article we will talk about the JavaScript sort method, which is useful for sorting the elements of an array. The syntax of the sort() method is as follows: array.sort(). You can also indicate a comparison function for which the syntax becomes: array.sort(comparison function). The comparison function is therefore optional and therefore the sorting … Leggi tutto

JavaScript map

map JavaScript

In this lesson we will talk about the JavaScript map method, used with arrays. This method creates a new array with the results of calling a function for each element of the starting array. The syntax is as follows: array.map(function) Where function can be an already existing function such as the absolute value function: Math.abs. … Leggi tutto

JavaScript array indexOf

indexOf JavaScript

The JavaScript array indexOf method, returns the starting position of an element within an array or string. The syntax of this method is as follows: array.indexOf(element) Where element is therefore the element whose position you want to know. As with the includes method, also in this case, you can optionally specify the position from which … Leggi tutto

JavaScript array length

Length JavaScript

The length property used on arrays in JavaScript is useful for determining how many elements are contained in an array. This property is also used to determine the length of a string. The syntax is very simple: ArrayName.length. Where with nomeaArray we indicate the array of which you want to calculate the length. JavaScript array … Leggi tutto

JavaScript add attribute

JavaScript add attribute

We study some JavaScript methods to add an attribute to elements. In particular, in this lesson we will use createAttribute() and setAttributeNode(). In the previous article we saw how to create new elements such as paragraphs, levels, titles, etc … JavaScript add attribute – createAttribute With the createAttribute() method you can add one or more … Leggi tutto