You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							26 lines
						
					
					
						
							770 B
						
					
					
				
			
		
		
	
	
							26 lines
						
					
					
						
							770 B
						
					
					
				| "use strict"; | |
|  | |
| function main(formName) { | |
| 	let result = document.getElementById("result"); | |
| 	let text = document.forms[formName].elements[0].value; | |
| 	let letter = document.forms[formName].elements[1].value; | |
| 	 | |
| 	result.textContent = "Результат: " + changeText(text, letter); | |
| } | |
|  | |
| function changeText(text, letter) {  | |
|     let result = text.split(" "); | |
| 	let words = result.filter( elem => matchWord(elem, letter) ); | |
| 	result.forEach( (elem, index, array) =>  | |
| 		array[index] = matchWord(elem, letter) ? getWord(words) : elem ); | |
| 	return result.join(" "); | |
| } | |
|  | |
| function matchWord(word, letter) { | |
| 	return word.charAt(0).toUpperCase() == letter.toUpperCase()  | |
| } | |
|  | |
| function getWord(words) { | |
| 	let index = Math.floor(Math.random() * words.length); | |
| 	return words.splice(index, 1); | |
| }
 | |
| 
 |