/    Sign up×
Community /Pin to ProfileBookmark

Need your opinion :)

Hello folks!

I’m completely new to JavaScript and programming altogether. I’ve got a little experience in VBscript and that’s it, nothing special.
I’m armed only with the books that I read and with a lot of good will to learn something new.
So by now I have a basic knowledge of VBscript, HTML, CSS and JavaScript. I gave my self a task to write a simple script to test what I have
been learned so far.

My question is what do you think about the script that I have been posted here, the way I wrote it… Ok, I know that there is probably
a million of different ways to achive the same result, but… I want you to pay special attention to the FUNCTION section. What do you think about it?
Is it too complicated, too hard to follow the code??? ? I didn’t finished it yet but that is not important ?

Thanks in advance!

This is the script:

//————————————————————————-INITIALIZATION SECTION—————————————————————————————————–

var blnFirstCheck = “false”;
var blnSecondCheck = “false”;
var blnThirdCheck = “false”;
var blnFourthCheck = “false”;
var blnTryAgain = “false”;
var blnWhileLoop = “true”;
var blnInnerWhileLoop = “true”;
var strMathOperation;
var strUserChoice;
var strToConc;
var intNumber;
var result;

//————————————————————————MAIN PROCESSING SECTION———————————————————————————————————

while (blnWhileLoop != “false”)
{
blnFirstCheck = “true”;
strUserChoice = prompt(“Select one of the options:” + “n” + “1.String concatenation” + “n” + “2.Mathematical operations”, “”);
checkUserInput(strUserChoice);
strUserChoice = Number(strUserChoice);
blnFirstCheck = “false”;
}

switch (strUserChoice)
{
case 1:
{
blnSecondCheck = “true”;
result = “”;
blnWhileLoop = “true”;

while (blnWhileLoop != “false”)
{
strToConc = prompt(“Enter one or more characters to concatenate together. To display final result, leave an input field empty and press OK button.”, “”);
checkUserInput(strToConc);
result = result + strToConc;
blnSecondCheck = “false”;
}
break;
}

case 2:
{
result = “”;
blnWhileLoop = “true”;

while (blnWhileLoop != “false”)
{
blnThirdCheck = “true”;
intNumber = prompt(“Enter a number: “, “”);
blnTryAgain = checkUserInput(intNumber);
if (blnTryAgain == “true”)
continue;
else
blnTryAgain = “false”;
intNumber = Number(intNumber);
blnThirdCheck = “false”;

while (blnInnerWhileLoop != “false”)
{
blnFourthCheck = “true”;
strMathOperation = prompt(“Select one of four possible math operations to perform.” +
“For addition ‘+’, subtraction ‘-‘, multiplication ‘*’, division ‘/’.”, “”)
checkUserInput(strMathOperation);
blnFourthCheck = “false”;
}
}
}

}
if (result == undefined)
result = “”;
document.write(“<p>” + “Result is: ” + “<span>” + result + “</span>” + “</p>”)

//—————————————————————————–FUNCTIONS————————————————————————————————————

function checkUserInput(strToCheck)
{
try
{
if (strToCheck == null || strToCheck == “”)
throw “See you!”;
if (isNaN(strToCheck) == true && blnSecondCheck != “true” && blnFourthCheck != “true”)
throw “Only numbers are allowed, please try again.”;
else
if (blnFourthCheck == “true” && isNaN(strToCheck) == false)
throw “Please select one of for possible operators.”
if ((strToCheck.length > 1) && (blnFirstCheck == “true” || blnFourthCheck == “true”))
throw “Please select only one option at a time.”;
if ((blnFourthCheck == “true”) && (strToCheck != “+” && strToCheck != “-” && strToCheck != “*” && strToCheck != “/”))
throw “Please select one of for possible operators.”
if ((blnSecondCheck == “true” || blnThirdCheck == “true”) && (strToCheck != null || strToCheck != “”))
blnWhileLoop = “true”;
if (blnFourthCheck == “true”)
blnInnerWhileLoop = “false”;
else
blnWhileLoop = “false”;
}
catch(error)
{
if (error == “See you!” || error == “”)
if (blnFirstCheck == “true”)
{
alert(error);
blnWhileLoop = “false”;
}
else
blnWhileLoop = “false”;
else
{
alert(error);
if (blnThirdCheck == “true”)
return “true”;
}
}
return;
}

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@tech_soul8authorOct 05.2012 — ...I just discovered that if you choose first choise code doesn't run as it should becouse I made a mistake when I was adding fourth check but as I said it doesn't matter. I just wanna know if it looks like something or not ?
Copy linkTweet thisAlerts:
@xelawhoOct 05.2012 — I can confirm that it does indeed look like something
×

Success!

Help @tech_soul8 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...