Tutorials related chat. For other discussions please join https://gitter.im/codebar/chat
KimberleyCook on gh-pages
Replace use of 'join' function … Merge pull request #480 from bd… (compare)
KimberleyCook on gh-pages
add more youtube links (compare)
KimberleyCook on add-youtube-links-to-some-tutorials
KimberleyCook on gh-pages
add youtube links for further l… Merge pull request #479 from co… (compare)
KimberleyCook on add-youtube-links-to-some-tutorials
add youtube links for further l… (compare)
KimberleyCook on gh-pages
update README with correct Bund… Merge pull request #476 from ro… (compare)
KimberleyCook on gh-pages
Update old links Merge pull request #478 from ro… (compare)
Hi: I'm practising exercises from Head First Javascript Programming (p.101).
I write the code in the book in the console and it gives me an error: points is not defined. It's not necessary to define a variable points for the parameters, right? Thanks in advance.
var avatar = "generic";
var skill = 1.0;
var pointsPerLevel = 1000;
var userPoints = 2008;
function getAvatar(points){
var level = points / pointsPerLevel;
if (level == 1) {
return "Teddy bear";
} else if (level == 1) {
return "Cat";
} else if (level >= 2) {
return "Gorilla";
}
};
function updatePoints(bonus, newPoints) {
var i = 0;
while(i<points){
newPoints = newPoints + skill * bonus;
i = i + 1;
}
return newPoints + userPoints;
}
userPoints = updatePoints(2,100);
avatar = getAvatar(2112);
while (i < points)
points
doesn't appear to be defined in the scope of updatePoints
I mean.
Hi everyone,
I'm practising Javascript with exercises from two books. They explain not to use global variables but then in the examples, they use them very often. So I'd like to rewrite this example from Javascript Head First, so that it's all done with locals. But my version is not completely right...So I'd appreciate your comments. Thanks in advance.
The code from the book:
var avatar = "generic";
var skill = 1.0;
var pointsPerLevel = 1000;
var userPoints = 2008;
function getAvatar(points){
var level = points / pointsPerLevel;
if (level == 1) {
return "Teddy bear";
} else if (level == 1) {
return "Cat";
} else if (level >= 2) {
return "Gorilla";
}
};
function updatePoints(bonus, newPoints) {
var i = 0;
while(i<bonus){
newPoints = newPoints + skill * bonus;
i = i + 1;
}
return newPoints + userPoints;
}
userPoints = updatePoints(2,100);
avatar = getAvatar(2112);
My version with locals - but gives me undefined...
function getAvatar(points){
var pointsPerLevel = 1000;
var level = points / pointsPerLevel;
if (level == 1) {
return "Teddy bear";
} else if (level == 1) {
return "Cat";
} else if (level >= 2) {
return "Gorilla";
}
};
function updatePoints(bonus, newPoints) {
var i = 0;
var skill = 1.0;
var userPoints = 2008;
while(i<bonus){
newPoints = newPoints + skill * bonus;
i = i + 1;
}
return newPoints + userPoints;
}
function init(){
userPoints = updatePoints(2,100);
var avatar = getAvatar(2112);}
level == 1
. you should always use ===
not ==
in the book,
there is the default value of 'avatar' so it seems to work well even though it is weird there is the same condition twice,
but in your version,
the return value of getAvatar() hasn’t the default one.
So if level is not equal to 1,2 or greater than 2, getAvatar() will return undefined…
you could code like following...
getAvatar(){
if(){..}
else if() {..}
return ‘generic’;
}
That is just my guess, so it might be wrong...
Hi: I'd like to know how to create a .gitignore file from the command line to exclude .idea related files. I don't know what do I need to exclude.
Or if this is just a txt.file.
I have this:
'code'
Carolinas-MBP:first_git_project carolina$ git add .
Carolinas-MBP:first_git_project carolina$ git commit -m "Initial commit"
[master (root-commit) 19c3842] Initial commit
9 files changed, 394 insertions(+)
create mode 100644 .idea/.name
create mode 100644 .idea/compiler.xml
create mode 100644 .idea/copyright/profiles_settings.xml
create mode 100644 .idea/first_git_project.iml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/vcs.xml
create mode 100644 .idea/workspace.xml
create mode 100644 first_file.html
Carolinas-MBP:first_git_project carolina$ .idea/
-bash: .idea/: is a directory
Carolinas-MBP:first_git_project carolina$
'code'
I know that inside the .gitignore file I can add this:
.idea/workspace.xml
.idea/modules.xml
Thanks!
echo .idea >> .gitignore
will add ".idea" to the ignore
echo ".idea" >> .gitignore
>
because that will overwrite the file rather than append to it
Shall I ignore the .gitignore "untracked files" and the "changes not staged for commit"? Here's the console.
"code"
Carolinas-MBP:first_git_project carolina$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: .idea/misc.xml
modified: .idea/workspace.xml
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
no changes added to commit (use "git add" and/or "git commit -a")
Carolinas-MBP:first_git_project carolina$
"code"
Thanks.
.idea/
in your .gitignore
yes, but now if I do git status I get changes not staged for commit and lists the .idea files that I modified. And also says that I have an untracked file, .gitingore.
In the .gitingore I have all this:
.idea/.name
.idea/compiler.xml
.idea/copyright/profiles_settings.xml
.idea/first_git_project.iml
.idea/misc.xml
.idea/modules.xml
.idea/vcs.xml
.idea/workspace.xml
.gitignore
, that cheeky beggar lives in git alongside your project
.git/
folder in the project, do a git init
and just re-add the files you do care about