0% found this document useful (0 votes)
29 views2 pages

PT Code For AP CS Exam

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

PT Code For AP CS Exam

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

onEvent("checker", "click", function( ) {

updateScreen();
updateScreen2();
});

//Code From:https://studio.code.org/s/csp7-2020/stage/6/puzzle/3
//Sets the text on how many vowels were in the input
//Modified to work for my program
function updateScreen(){
var text = getText("wordinput");
var statement = vowel_count(text);
setText("text_area3","Number of Vowels: " + statement);
}

// Code From:https://studio.code.org/s/csp7-2020/stage/6/puzzle/3
//Sets the text area on how many nonvowels are in the input
//Modified to work with my program
function updateScreen2(){
var text = getText("wordinput");
var statement = nonvowel_count(text);
setText("text_area4","Number of NonVowels: " + statement);
}
//Citied:https://www.w3resource.com/javascript-exercises/javascript-function-exercise-7.php
//vowel and nonvowel counter
function vowel_count(str1)
{
var vowel_list = 'aeiouAEIOU';
var vcount = 0;

for(var x = 0; x < str1.length ; x++)


{
if (vowel_list.indexOf(str1[x]) !== -1)
{
vcount += 1;
}
}
return vcount;
}

//Citied:https://www.w3resource.com/javascript-exercises/javascript-function-exercise-7.php
//Modified the previous code to count how many
//letters arent vowels and add to a counter to check
//Only checks for letters uppercase and lower,not numbers or symbols
function nonvowel_count(str1)
{
var nvowel_list = 'BCDFGHJKMNPQRSTVWXYZLbcdfghjkmnpqrstvwxyzl';
var nvcount = 0;

for(var x = 0; x < str1.length ; x++)


{
if (nvowel_list.indexOf(str1[x]) !== -1)
{
nvcount += 1;
}
}
return nvcount;
}

You might also like