wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if num = 6 then print('world') end
if num == 6 then print('world') end
Use ==.
Lua
int temp = 'message';
String temp = 'message';
Type mismatch.
Dart
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
let z: number = 'test';
let z: string = 'test';
Fix type.
TypeScript
if num = 23
if num == 23
Use ==.
Ruby
if [ $num = 53 ]; then
if [ "$num" = 53 ]; then
Quote variable.
Shell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
String item = 'result';
String item = "result";
Double quotes.
Java
{{'status':'result'}}
{{"status":"result"}}
Use double quotes.
JSON
let str = String::from("result"); let ref=&str; str.push_str("!");
let mut str = String::from("result"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
if (item = 89)
if (item == 89)
Use ==.
R
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
function handle() {{ echo 'hello'; }}
function handle() {{ echo 'hello'; }}
Correct.
PHP
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for x in range(78) print(x)
for x in range(78): print(x)
Colon after for.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (foo = 41) {{}}
if (foo == 41) {{}}
Use ==.
Java
class User def method end end
class User def method end end
Correct.
Ruby
status: message title: data,
status: message title: data
Remove comma.
YAML
if foo > 38 puts 'data'
if foo > 38 puts 'data' end
Add 'end'.
Ruby
while temp > 79 temp -= 1
while temp > 79: temp -= 1
Colon missing after while.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let str1 = String::from("message"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<hr></hr>
<hr>
Self-closing.
HTML
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(45);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(45);
Correct.
Node.js
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(4);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(4, () => console.log('listening'));
Add callback.
Node.js
let z = 14; let z = 49;
let z = 14; z = 49;
Duplicate declaration.
JavaScript
yield temp
yield temp
Correct yield.
Python
$values[21] = 5;
if (isset($values[21])) $values[21] = 5;
Check existence.
PHP
if (item = 71) {{}}
if (item === 71) {{}}
Use === for equality.
JavaScript
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
let temp: Int = 'value'
let temp: String = 'value'
Fix type.
Swift
if (y = 35)
if (y == 35)
Use ==.
Scala
const y;
const y = 98;
Initialize const.
JavaScript
let c = 30;
let c = 30;
Correct.
JavaScript
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
data.forEach(function(x) {{ console.log(x); }})
data.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
[81, 64, 94
[81, 64, 94]
Close bracket.
Ruby
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for (z in data)
for (z of data)
for...in iterates keys.
JavaScript
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
// comment
/* comment */
Use /* */.
CSS
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
fn foo() -> i32 {{ 76 }}
fn foo() -> i32 {{ 76 }}
Correct.
Rust
let data = 82; data += 1;
let mut data = 82; data += 1;
Need mut to modify.
Rust
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
var val int = 'value'
var val string = 'value'
Type mismatch.
Go
SELECT age email FROM users;
SELECT age, email FROM users;
Add comma.
SQL
count = data
count = 'data'
Quote strings.
Python
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
$values[86]
if ($values.Count -gt 86) {{ $values[86] }}
Check bounds.
PowerShell
arr(64)
if length(arr) >= 64, arr(64), end
Check length.
MATLAB
list[90]
if (length(list) >= 90) list[90]
Check length.
R
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
WHERE id = '47'
WHERE id = 47
Don't quote integer.
SQL
while a > 56 a -= 1
while a > 56: a -= 1
Colon missing after while.
Python
object Person {{ def main(args: Array[String]) = println("data") }}
object Person {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
jwt.sign({{id:20}}, 'secret');
jwt.sign({{id:20}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
let data = 91;
let data = 91;
Correct.
JavaScript
var z int = 'test'
var z string = 'test'
Type mismatch.
Go
'message' + 57
'message' + str(57)
Can't add int to string.
Python
echo 'hello'
echo 'hello';
Add semicolon.
PHP
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
let b = 82; b += 1;
let mut b = 82; b += 1;
Need mut to modify.
Rust
function render() {{ return {{key:'message'}} }}
function render() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
DELETE FROM items WHERE email=84
DELETE FROM items WHERE email=84;
Add semicolon.
SQL
function bar(x:string){{return x;}} bar(70);
function bar(x:string){{return x;}} bar('output');
Pass correct type.
TypeScript
values[94]
if (values.indices.contains(94)) values[94]
Check index.
Kotlin
arr[99]
if arr.indices.contains(99) {{ arr[99] }}
Check index.
Swift
if ($data = 14) {{}}
if ($data -eq 14) {{}}
Use -eq.
PowerShell
print 'hello'
print('hello')
Parentheses for function call.
Lua
[86, 61, 47
[86, 61, 47]
Close bracket.
Python
else print('output')
else: print('output')
Colon after else.
Python
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
38item = 10
item38 = 10
Variable cannot start with digit.
Python
UPDATE products SET status='hello' WHERE status=33
UPDATE products SET status='hello' WHERE status=33;
Add semicolon.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
{{'age':95, 'age' 63}}
{{'age':95, 'age':63}}
Colon missing.
Python
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
int x = 'message';
String x = 'message';
Type mismatch.
Dart
if [ $z = 91 ]; then
if [ "$z" = 91 ]; then
Quote variable.
Shell
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
yield temp
yield temp
Correct yield.
Python
<hr></hr>
<hr>
Self-closing.
HTML
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
$x = 84; if ($x = 84) {{}}
$x = 84; if ($x == 84) {{}}
Use ==.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (foo = 8) {{}}
if (foo === 8) {{}}
Use === for equality.
JavaScript
fn compute() -> i32 {{ 1 }}
fn compute() -> i32 {{ 1 }}
Correct.
Rust