3.8 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			3.8 KiB
		
	
	
	
	
	
	
	
title
| title | 
|---|
| Declare a Read-Only Variable with the const Keyword | 
 Remember to use
 Remember to use Read-Search-Ask if you get stuck. Try to pair program  and write your own code
 and write your own code 
Problem Explanation:
Change all the variables to let or const and rename sentence.
 Hint: 1
 Hint: 1
- Replace varfor string with read-onlyconst.
try to solve the problem now
 Hint: 1
 Hint: 1
- Replace varinforloop tolet.
try to solve the problem now
 Hint: 1
 Hint: 1
- Common convention is to name constvariables with ALL CAPS.
try to solve the problem now
Spoiler Alert!
Solution ahead!
 Basic Code Solution:
 Basic Code Solution:
    function printManyTimes(str) {
      "use strict";
      const SENTENCE = str + " is cool!";
      for(let i = 0; i < str.length; i+=2) {
        console.log(SENTENCE);
      }
    }
    printManyTimes("freeCodeCamp");
Code Explanation:
By using const on sentence we can make it read-only and by using let on i inside the for loop we can avoid using var all together. For added code clarity we can also change sentence to SENTENCE to show that it is a constant.
Relevant Links
 NOTES FOR CONTRIBUTIONS:
 NOTES FOR CONTRIBUTIONS:
 DO NOT add solutions that are similar to any existing solutions. If you think it is similar but better, then try to merge (or replace) the existing similar solution. DO NOT add solutions that are similar to any existing solutions. If you think it is similar but better, then try to merge (or replace) the existing similar solution.
- Add an explanation of your solution.
- Categorize the solution in one of the following categories — Basic, Intermediate and Advanced.  
- Please add your username only if you have added any relevant main contents. ( DO NOT remove any existing usernames) DO NOT remove any existing usernames)
See

Wiki Challenge Solution Templatefor reference.


