اذهب إلى المحتوى
  • 0

جافا سكريبت

Lugain Amer

السؤال

read (from key board)15 integer values into an array all values must be between 100 and 200 then write the following: a- Function to find the square root for the largest value in the array and return it to main to print it. b- Function to find the square roots for all array values and print them from the Function c- Function to count the number of values that are between 120 and 145(145 و 120 بین المحصورة المصفوفة في القیم عدد (the function returns it to main to print it. d- Function to find the smallest and largest values in the array and print them .

SECOND-ASSINMENT.pdf

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 1

مرحباً بك @Lugain Amer.

هذا هو حل المسألة:

<script>

var numbers = window.prompt("Write 15 integers between 100 and 200: ");
var numArray = numbers.split(" ");


function square_of_largest_num(numArray){
	var largest= 0;
	for (i=0; i<=largest;i++){
    	if (numArray[i]>largest) {
        	var largest=numArray[i];
    	}
	}
    
    var largest = Math.sqrt(largest);
    alert(largest);
}

function square_of_all_nums(numArray){
	for( i = 0; i < numArray.length; i++){
		alert(`Square root of ${numArray[i]} is ${ Math.sqrt(numArray[i])}`);
	}
}


function count_values_between_120_145(numArray){
	var count = 0;
	for( i = 0; i < numArray.length; i++){
    	if(numArray[i] >= 120 && numArray[i] <= 145){
        	count++;
        }
    }
    return count;
}

function find_smallest_and_largest_num(numArray){
	var largest= 0;
	for (i=0; i<=largest;i++){
    	if (numArray[i]>largest) {
        	var largest=numArray[i];
    	}
	}
    
    var smallest = Math.min.apply(Math, numArray)
    alert(`Largest number is ${largest} and Smallest number is ${smallest}`);
}

square_of_largest_num(numArray);

square_of_all_nums(numArray);

var count = count_values_between_120_145(numArray);
alert(`Count of values between 120 and 145 is ${count}`);

find_smallest_and_largest_num(numArray);
</script>




 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...