Creating a program from flowchart

8,944 views

Published on

Published in: Career, Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
8,944
On SlideShare
0
From Embeds
0
Number of Embeds
6,383
Actions
Shares
0
Downloads
35
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Creating a program from flowchart

  1. 1. How to create a programA simple guide to help you better understand theprocess
  2. 2. 1.Example programCreate a program that produces the following-1.Input a number2.Find out if the number is a multiple of 3
  3. 3. 2.Create a flowchartSo if the output has more than one answer, itwould be conditional instructions so we mustinclude a decision box within the flowchart.
  4. 4. 3.Creating the flowchartTo help us with coding, we should createvariable names for the data we will input.So if the instruction is to input a number then wewill call it var numb.*variables are case-sensitive and cannot includespaces or punctuation marks.
  5. 5. 4.The flowchart
  6. 6. The code<html><body><script type="text/javascript">var numb = prompt("enter number to check if it is a multiple of 3","");numb= parseInt(numb);var remainder=numb%3;if(remainder%3!=0){document.write("no");}else{document.write("yes");}</script></body></html>
  7. 7. 5.Using the flowchart to help createcode in javascript<html><body><scripttype="text/javascript">
  8. 8. 5.Using the flowchart to help usecode in javascriptHere we create thecode so the programwill ask the user toenter a number andwe assign the variableto a function.var numb =prompt("enter numberto check if it is amultiple of 3","");numb= parseInt(numb);
  9. 9. 5.Using the flowchart to help usecode in javascriptThis % is amathematical operatorwhich will present aremainder if a numberis divided. The ifstatement checks if acode divides by 3 witha remainder.var remainder=numb%3;if(remainder%3!=0)
  10. 10. 5.Using the flowchart to help usecode in javascriptThe “!=0” states tocheck if the remainderis not equal to 0 sincea multiple woulddivide and have noremainder.var remainder=numb%3;if(remainder%3!=0)
  11. 11. 5.Using the flowchart to help usecode in javascriptSo if code divides by 3 with aremainder, the if statement willproduce output that reads “no”meaning the number entered inthe program is not a multiple of3. If there is any other numberthat does divide by 3 with noremainder it will display yes.{document.write("no");}else{document.write("yes");}
  12. 12. 5.Using the flowchart to help usecode in javascriptWe then end theprogram with this-</script></body></html>
  13. 13. 5.Using the flowchart to help usecode in javascriptWe then end theprogram with this-</script></body></html>
  14. 14. SummaryCreate a flowchart to help you when coding aprogram.Remember that variables usually begin with“var” and are case-sensitive.Document.write is used to produce an output.Assign a variable using parseInt I.e var age =parseInt (age.)*If a code doesnt work, you can check online tosee what could be wrong with the code.

×