11484 sujets

JavaScript, DOM et API Web HTML5

Bonjour à tous,

Je coince méchant sur un calcul du nombre de note dans un ficher musicale.

Dans la function compteNotes(), la console me retourne toujours ce erreur: TypeError: notesValidee.push is not a function.

function compteNotes(output,chaine) {
	var notes = Array('a','ais','aes','b','bis','bes','c','cis','ces','d','dis','des','e','eis','ees','f','fis','fes','g','gis','ges');
	var str = chaine.toString();
	var exp = new RegExp('[abcdefgis]+','g');	
	var tabNom=str.match(exp);
	var notesValidee=Array();
	for(var i=0;i<tabNom.length;i++){
		if (notes.includes(tabNom[i]) == true){ 			
			notesValidee.push(tabNom[i]); 
			}else{
			notesValidee = "Rien";
			}			
		}	
	
	console.log("notesValidee: "+notesValidee+' tabNom[0]: '+tabNom[1]+' tabNom.length: '+tabNom.length+' type: '+typeof tabNom);
	var nbcara=str.length;
	if ( tabNom.length >  1 ) {	
		tabNom = notesValidee;
		var affichage='' + tabNom.length + '';
		document.getElementById(output).innerHTML = "Cette partition compte "+affichage+" notes. ";
		tabNom = tabNom.toString();
		var res=tabNom.match(/(.{1,100})/g);		
		document.getElementById(output+"0").innerHTML = "Notes sélectionnée: "+ res.join("</br>"); //.match(/.{0,20}/g);
		}else {	
		document.getElementById(output).innerHTML = "La chaine n'est pas valide. Il ne contient aucune note. Voyez ci-dessous:	</br>"+tabNom+"<hr>";
		
		}
	}


Il doit certainement y avoir une erreur mais je ne vois pas ou!!!

Voici le code entier sur https://jsfiddle.net/Larix/h4tjx1gv/5/

Je me réjouis de voir ce que j'ai loupé.

Cordiales salutations à tous.

Stéphane
Bonjour nabucco,
Dans ta condition tu transformes :
notesValidee = "Rien"; en string ce n'est donc plus un tableau
Meilleure solution