<div id="display" style="width:100%;height:auto;">
<p>
Wat is de waarde van result na uitvoer indien deze x de volgende waarden aanneemt?
</p>
</div>
CSS
p {line-height:0.5em;}
JavaScript
//De te testen waarden in een array plaatsen
var testvalues = [2,3,4,5,6,7,8,9,10,11,23];
//Door de array loopen
for(var pArray=0, len=testvalues.length; pArray < len; ++pArray){
//Geef p de waarde van de array
var p=testvalues[pArray];
//We starten met result altijd gelijk aan true
var result = true;
//De gevraagde test loop
for (var i=2; i*i <= p; ++i){
if (p % i === 0){
result = false;
}
//Laat de variabelen die getest worden zien via een functie oproep
testResults(i,p,result);
}
//Laat het resultaat zien
var temp = document.getElementById("display").innerHTML;
temp += "<p style='font-weight:bold;'>Indien p=" + p + ", dan is result = " + result + "</p><hr/>";
document.getElementById("display").innerHTML = temp;
}
function testResults(iVal,pVal,resultVal){
var temp = document.getElementById("display").innerHTML;
temp += "<p>i=" + iVal + " : i*i (" + i*i +") <= p (" + pVal +") ? Bewerking p % i = " + pVal%iVal + " Variabele result = " + result + "</p>";
document.getElementById("display").innerHTML = temp;
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.