subject

Need help with APCSP coding (for and while loops) It says that there are two codes that can be shortened into for/while loops. Please hurry, I have to pass it at 11:59 tonight (PST). I'll give brainliest if you answer.

Here's the code:

var monthName="January";

var month=1;

var day=1;

var year=2020;

var birthDate = "";

onEvent("input1","input",function () {

monthName = getText("input1");

month = convertToNumber(monthName. toLowerCase());

updateScreen();

});

onEvent("input2","input",function () {

day = getNumber("input2");

updateScreen();

});

onEvent("input3","input",function () {

year = getNumber("input3");

updateScreen();

});

onEvent("checkButton","click",fun ction () {

var d = new Date();

var todayMonthNum = d. getMonth()+1;

var todayDay = d. getDay();

var todayYear = d. getFullYear();

if (todayMonthNum == month &&

todayDay == day &&

todayYear == year)

{

hideElement("input1");

hideElement("input2");

hideElement("input3");

playSound("EJGreenberg---birthday-b irthday. mp3");

}

});

function updateScreen ()

{

birthDate =month + "/" + day + "/" + year;

setText("dateOutput",birthDate);

}

function convertToNumber (name)

{

var names=["january", "february", "march", "april",

"may", "june", "july", "august",

"september", "october", "november", "december"];

var foundIndex = -1;

if (names[0]==name) foundIndex = 0;

if (names[1]==name) foundIndex = 1;

if (names[2]==name) foundIndex = 2;

if (names[3]==name) foundIndex = 3;

if (names[4]==name) foundIndex = 4;

if (names[5]==name) foundIndex = 5;

if (names[6]==name) foundIndex = 6;

if (names[7]==name) foundIndex = 7;

if (names[8]==name) foundIndex = 8;

if (names[9]==name) foundIndex = 9;

if (names[10]==name) foundIndex = 10;

if (names[11]==name) foundIndex = 11;

if (foundIndex==-1) return "??";

else return foundIndex + 1;

}

ansver
Answers: 1

Another question on Advanced Placement (AP)

question
Advanced Placement (AP), 23.06.2019 12:50
Ill give you free points and brainliest if you me with the correct answer every time you hit the brakes, you are attempting to overcome a. potential energy b. kinetic energy c. static electricity d. the force of impact
Answers: 2
question
Advanced Placement (AP), 23.06.2019 14:00
How can firms use marginal analysis to determine the price of a product? a) profit maximization can occur when the marginal cost exceeds the marginal revenue. b) the total cost of production can determine the individual unit price of a product. c) marginal analysis can be used to determine at what price profit maximization occurs. d) firms can calculate the marginal cost of a product and set the price lower than the cost.
Answers: 2
question
Advanced Placement (AP), 24.06.2019 00:30
Which body region is lateral to the sternal region and superior to the brachial region?
Answers: 1
question
Advanced Placement (AP), 24.06.2019 21:30
Hey guys! this is not for school. i my dog gave birth a week ago and we are celebrating them today so i decided to give out a ton of points, a tnx and brainiest to whoever answers the following questions. 1. did you have a good day today. 2. do you like dogs (its okay if you don’t) 3. if you were an animal, what animal would you be? (i am just curious. i would be a unicorn.)
Answers: 2
You know the right answer?
Need help with APCSP coding (for and while loops) It says that there are two codes that can be shor...
Questions
question
History, 18.05.2021 17:30
question
History, 18.05.2021 17:30
question
Mathematics, 18.05.2021 17:30
question
Arts, 18.05.2021 17:30
question
Spanish, 18.05.2021 17:30
question
Geography, 18.05.2021 17:30
Questions on the website: 13722360