1

I don't want to run the Python code inside Javascript, I want to turn it completely into JS code. I have no idea about python, Can body can help me on this. Thank you.

print ("Please input the # of books you've read this year") 
BooksAlready=int(input())
print ("Please input the # of weeks that have already passed this year") 
WeeksAlready=int(input())
x=(78/52)
c=x*WeeksAlready-BooksAlready
if (BooksAlready/WeeksAlready)>x:
 print ("You're on point, go have some fun!")
else:
 print ("Go read, you piece of uneducated crap")
 print ("You have")
 print (c)
 print ("books left to read this week to get on point")
Cfreak
19.4k6 gold badges52 silver badges64 bronze badges
asked Mar 29, 2017 at 4:42
6
  • Presumably you want this to run in a terminal like NodeJS? Commented Mar 29, 2017 at 4:45
  • 1
    Possible duplicate of Python to Javascript converter Commented Mar 29, 2017 at 4:45
  • 1
    This might help you-stackoverflow.com/questions/22595989/… Commented Mar 29, 2017 at 4:47
  • If you just need it to run in a JS environment, apparently some tools do exist -- although I'm a bit dubious of cross-language transpilation. Or is this an exercise-- where you want to do it to learn about Python? Commented Mar 29, 2017 at 4:47
  • @anied yes I want to run this in JS environment. I want to convert into pure Js Commented Mar 29, 2017 at 4:51

2 Answers 2

2

This will run in the browser's js console. prompt will not work in node.js, you can access a commandline argument with process.argv.

console.log("Please input the # of books you've read this year");
console.log("Please input the # of weeks that have already passed this year");
var WeeksAlready=parseInt(prompt()),
BooksAlready=parseInt(prompt()), 
x=(78/52),
c=x*WeeksAlready-BooksAlready;
if (BooksAlready/WeeksAlready>x){
 console.log("You're on point, go have some fun!");
}
else{
 console.log ("Go read, you piece of uneducated crap");
 console.log ("You have");
 console.log (c);
 console.log ("books left to read this week to get on point"); 
}
answered Mar 29, 2017 at 4:52
Sign up to request clarification or add additional context in comments.

Comments

0

Please check below links to know more about converters from python to js.

http://www.infoworld.com/article/3033047/javascript/4-tools-to-convert-python-to-javascript-and-back-again.html

answered Mar 29, 2017 at 4:55

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.